"Marek Elsner" <marek icom pl> writes:
Hello, I know that this problem is very easy to solve, but I have no idea how to do it. Sorry but I am starting with XPath. :-) I have got xml file with two namespaces, one inside another. As I know when I have one namespace, I can register it, and after that query as "//namespac_name:node" but how to do queries, when I have another namespace in namespace_name, and I want to find a node inside two namespaces...? thanks for help Marek Elsner
A node can only belong to one namespace. If there are more than one xmlns declarations for the same prefix (or without a prefix) in an XML document, then the inner-most declaration (in the scope of which the node occurs) counts, i.e. in <foo1 xmlns="bar"> <foo2/> <foo3 xmlns="baz"> <foo4/> </foo3> </foo1> foo1 and foo2 belong to namespace "bar" whereas foo3 and foo4 belong to "baz". It is however much less confusing to use distinct namespace prefixes in such situations: <f:foo1 xmlns:f="bar"> <f:foo2/> <g:foo3 xmlns:g="baz"> <g:foo4/> </g:foo3> </f:foo1> What you may be looking for is how to express (in XPath) the fact that `a node belonging to the namespace "baz" descents from an element belonging to the namespace "bar"'. Provided you have registered the prefixes f and g with your xmlXPathContext, you could express that as //f:*//g:something /petr P.S. As these are rather general XML questions, not necessarily concerning libxml2, I'm not quite sure they should be addressed to this list (apart from the fact that there is a plenty of sources where you could find your answers just by reading them - if you don't want to go through the w3c specs, have a look at http://zvon.org for instance).
Description: PGP signature