|No such thing as a small change|
XML::LibXML findnodes and namespacesby shamu (Acolyte)
|on Mar 28, 2007 at 05:16 UTC||Need Help??|
shamu has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to migrate some code from XML::Twig to XML::LibXML for it's performance advantages. I've been trying with great difficulty to use XML::LibXML to parse dynamically created XML in which the element namespaces are not known prior to parsing. I don't care what the default namespaces are, as long as they don't get in the way.
I'm attempting to use findnodes with the recommended (from perlmonks) XML::LibXML::XPathContext module for dealing with the namespaces. Using registerNs doesn't appear to have any visible effect when printing the XML as a string, so I use $node->setNamespace to accomplish that.
I've read the two related posts to this topic: 555011 242028
...but I'm still stuck. It appears that when I encounter an element with a default namespace, findnodes refuses to match it without registering some prefix to the URI. I just want to be able to retrieve the nodes using an XPath like:
And if I want to create new elements with arbitrary namespaces, I don't want to have to manage the namespaces at every turn.Why does this work?
But not this?
Please help! :)I have an XML file like: