Skip to content

Instantly share code, notes, and snippets.

@shaunduncan
Last active December 26, 2015 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shaunduncan/7158256 to your computer and use it in GitHub Desktop.
Save shaunduncan/7158256 to your computer and use it in GitHub Desktop.
package main
import "fmt"
import xmlx "github.com/jteeuwen/go-pkg-xmlx"
var demo = `
<document>
<collection>
<category>One</category>
<category>Two</category>
<item>
<category>Three</category>
</item>
</collection>
</document>
`
func main() {
doc := xmlx.New()
if err := doc.LoadString(demo, nil); err != nil {
panic(err)
}
coll := doc.SelectNode("", "collection")
// I would expect this to print 2. It prints 3
fmt.Printf("Total: %d\n", len(coll.SelectNodes("", "category")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment