Looking at go xml package I could not find such possibility. Go only allows to define tree of structures, map them to XML tree and deserialize using xml.NewDecoder(myXmlString).Decode(myStruct)
.
Even if I define needed tree of Go structures, I still can't query that tree using XPath.
C# has convenient function SelectSingleNode that allows to select value from XML tree by specifying XPath without duplicating whole tree structure in C# classes.
Is there similar possibility in Go ? If not then what is simplest way to implement it (possibly reusing xml package) ?
XPath (XML Path Language) is a query language that can be used to query data from XML documents. In RUEI, XPath queries can be used for content scanning of XML documents.
There's also the xmlpath package.
Sample usage:
path := xmlpath.MustCompile("/library/book/isbn") root, err := xmlpath.Parse(file) if err != nil { log.Fatal(err) } if value, ok := path.String(root); ok { fmt.Println("Found:", value) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With