MCPcopy Create free account
hub / github.com/antchfx/xmlquery / TestAttributesNamespaces

Function TestAttributesNamespaces

query_test.go:132–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

130}
131
132func TestAttributesNamespaces(t *testing.T) {
133 doc := loadXML(`
134 <root xmlns="ns://root" xmlns:nested="ns://nested" xmlns:other="ns://other">
135 <tag id="1" attr="v"></tag>
136 <tag id="2" nested:attr="v"></tag>
137 <nested:tag id="3" nested:attr="v"></nested:tag>
138 <nested:tag id="4" other:attr="v"></nested:tag>
139 <nested:tag id="5" attr="v"></nested:tag>
140 </root>
141 `)
142 results := Find(doc, "//*[@*[namespace-uri()='ns://nested' and local-name()='attr']]")
143 parsed := make([]string, 0, 5)
144 for _, tag := range results {
145 parsed = append(parsed, tag.SelectAttr("id"))
146 }
147 got := fmt.Sprintf("%v", parsed)
148
149 // unsure if 5 should be selected here
150 if got != "[2 3]" {
151 t.Fatalf("Expected tags [2 3], got %v", got)
152 }
153}
154
155func loadXML(s string) *Node {
156 node, err := Parse(strings.NewReader(s))

Callers

nothing calls this directly

Calls 3

loadXMLFunction · 0.85
FindFunction · 0.85
SelectAttrMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…