|
|
| The stupid question is the question not asked | |
| PerlMonks |
Re^2: Namespaced XML::LibXML XPath query (not a bug)by Aristotle (Chancellor) |
| on Feb 19, 2006 at 19:53 UTC ( [id://531313]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
The behaviour you saw is absolutely correct and not a bug at all. To quote the author of libxml2 from a message aptly titled Re: [xml] XPath and default namespaces (bet you're sick of this by now :) ):
Google [daniel veillard default namespace xpath] if you want more. As he says, XPath has no notion of a default namespace. //lastName in an XPath expression always matches that element in the null namespace, not the default namespace. According to the spec:
In //sdnList:lastName, sdnList is not a namespace. Only URIs can be namespaces. The stuff in front of the colon is the prefix, and is merely a stand-in for the URI. <sdnList xmlns="http://tempuri.org/sdnList.xsd"> puts the sdnList element (and all its prefix-less descendants) in the http://tempuri.org/sdnList.xsd namespace. You have to associate this URI with a prefix, then use the prefix in your expression. This is exactly the approach lestrrat posted:
I wrote about this a while ago. Note that the prefix is arbitrary and has nothing to do with what appears in your document. This is as it should be, because the following document means exactly the same as the one you have:
For that matter, even this means the same:
Or this:
You get the idea. Makeshifts last the longest.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||