(t *testing.T)
| 130 | } |
| 131 | |
| 132 | func 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 | |
| 155 | func loadXML(s string) *Node { |
| 156 | node, err := Parse(strings.NewReader(s)) |
nothing calls this directly
no test coverage detected
searching dependent graphs…