|go ahead... be a heretic|
Re: LibXML, Namespaces, xpath expression - This should be simple.by FalseVinylShrub (Chaplain)
|on Sep 03, 2011 at 15:59 UTC||Need Help??|
There was something wrong with you example XML, the MyImportantNode elements were closed before defining the attributes.
Assuming that was an error in posting, I think that your confusion comes from a number of reasons:
In 1 it is something to do with the way you are chaining findnodes and string_value. If you replace it with:
you'll get Random1Random2Random3. If you want to deal with each value, you'll need a loop:
Having said that, it's a bit confusing that you're using nodeybits (the MiddleTag node) but then running XPath expressions beginning with "//", which will start at the root.
2 does what I'd expect, given the above: the first tag that matches that will be the root element, and calling string_value on that will return the entire text of the file.
The remaining ones are all because you're using $nodeybits. This is not an XPathContext object. For the examples you've given, you could use $xpc. But presumably this is cut down from a bigger program where you're doing XPath relative to the node you're looking at in the loop.
EDIT see ikegami's reply
Worked for me and you could use $inner_xpc for your remaining queries, being careful to be consistent about using the namespace prefix (in 5, you have theNS:RootTag but miss it off for all the other element names).
Disclaimer: Please review and test code, and use at your own risk... If I answer a question, I would like to hear if and how you solved your problem.