I have an XML struct like this.
<Process>
<Name> Process1 </Name>
<SQLFile> aSQLFile.sql </SQLFile>
<SQLText> select * from Items <SQLText>
<Mode> 2 </Mode>
<Process>
I am using the etree XML package to work with this XML: beevik/etree
In the sample code below, a list of this XML struct is called elems
. I am calling this code to walk through a list of elems
in an XML document:
for err, elemA := range elems.FindElements("//Name") {
err, elemB:=elemA.FindElement(//SQLFile){
doSomething(elemB)
}
This code works – doSomething(elemB)
– does what it is supposed to do, but according to the etree comments on FindElement
, it should fail. elemB
should be nil
:
FindElement returns the first element matched by the XPath-like
‘path’ string. The function returns nil if no child element is found
using the path.
According to that comment, elemB:=elemA.FindElement(//SQLFile) should return nil
, because <SQLFile>
is a sibling of <Name>
, not a child.
Why isn’t elemA.FindElement(//SQLFile)
returning nil
in this code?