|Don't ask to ask, just ask|
XML::LibXML and XML Namespaces (processing OpenOffice documents)by tomhukins (Curate)
|on Mar 11, 2003 at 14:07 UTC||Need Help??|
tomhukins has asked for the wisdom of the Perl Monks concerning the following question:
I want to use XML::LibXML to process OpenOffice (sxw) files. OpenOffice stores its information in a Zip archive containing several XML files. I have extracted the content.xml file from such an archive.
I have used XML::LibXML before, but never with XML documents that use namespaces. OpenOffice files use various namespaces for the different types of content.
Normally, I would write something like:
to retrieve all the nodes of type p. OpenOffice stores paragraphs in p elements within the text namespace. So, I replaced the findnodes line above with:
but this returns the error XPath error Undefined namespace prefix in //text:p xmlXPathCompiledEval: evaluation failed.
I fixed this problem with:
but I don't understand why one way works and the other way doesn't. Both contexts (tree and documentElement) work with another XML document that does not use namespaces.
Can anyone here enlighten me?