I couldn't find any PHP code on the net that would build the XPath to a node for me, so I wrote my own function.Turns out it wasn't as hard as I thought it might be (yay recursion), though it does entail using some PHP shenanigans...
It also defines the media types application/xml and text/xml, which say only that the data is in XML, and nothing about its semantics.
Yanick's contribution rocks - butit overwrote with duplicates only keeping the last linein the returned array.
All the other functions i tested from various sources failed to handle text nodes correctly. It is adapted from code on this site.function my Text Node($n, &$a) so you could use: $nodes = $dom- I found the xml2array function below very useful, but there seems to be a bug in it. I've expanded this out to be a bit more readable, and the corrected code is : function xml To Array($n) The project I'm currently working on uses XPaths to dynamically navigate through chunks of an XML file.
This means that text nodes, attribute values etc, should be in utf8.
"Programming with libxml2 is like the thrilling embrace of an exotic stranger." Mark Pilgrim Libxml2 is the XML C parser and toolkit developed for the Gnome project (but usable outside of the Gnome platform), it is free software available under the MIT License.