Closed srebhan closed 4 years ago
Use xpath.Eval() instead of xmlquery.Query()
. The xmlquery.Query()
function only executing a query(including logical operation) not do computing.
// Parse the XML
doc, err := xmlquery.Parse(strings.NewReader(xml))
if err != nil {
panic(err)
}
query = "substring-before(/Test/Variable/@Name, '-')"
exp := xpath.MustCompile(query)
v := exp.Evaluate(xmlquery.CreateXPathNavigator(doc))
fmt.Println(v.(string))
When executing the following code
with the first query, the node is found correctly and I do get the text of the attribute 'test-a-b/c' as expected.
However, when using the second query with
substring-before
I do get anil
node
and the print-out is 'Node is nil', when the expected result is the string 'test'.Is there an error in the code above or is this an issue in xmlquery?