[xml] xpath expression and namespaces
- From: Aleksey Sanin <aleksey aleksey com>
- To: xml gnome org
- Subject: [xml] xpath expression and namespaces
- Date: Tue, 28 May 2002 22:58:29 -0700
Daniel,
I have a strange problem with XPath expressions + namespaces and I would
like to get your opinion on this. Suppose we have following XML document:
<foo:Root xmlns:bar="http://example.org/bar"
xmlns:baz="http://example.org/baz"
xmlns:foo="http://example.org/foo"
xmlns="http://example.org/"
xml:lang="en-ie">
<bar:Something>
<foo:Something>
<bar:Something>
<foo:Something>
<baz:Something />
</foo:Something>
</bar:Something>
</foo:Something>
</bar:Something>
</foo:Root>
and the following XPath expression (in XMLDSig notation):
<XPath xmlns:bar="http://example.org/bar" >
(//. | //@* | //namespace::*)
[
ancestor-or-self::bar:Something and
(self::text() or (namespace-uri() != "") or
(string(self::node()) = namespace-uri(parent::node())))
]
</XPath>
The expectation is that this XPath expression will select the
bar:Something subtree,
but only includes namespace nodes that are directly used by their parent
element.
However, the LibXML results looks as follows (using xmlDebugDumpNode()):
ELEMENT bar:Something
TEXT
content=
ELEMENT foo:Something
TEXT
content=
ELEMENT bar:Something
TEXT
content=
ELEMENT foo:Something
TEXT
content=
ELEMENT baz:Something
TEXT
content=
TEXT
content=
TEXT
content=
TEXT
content=
TEXT
content=
ELEMENT foo:Something
TEXT
content=
ELEMENT bar:Something
TEXT
content=
ELEMENT foo:Something
TEXT
content=
ELEMENT baz:Something
TEXT
content=
TEXT
content=
TEXT
content=
TEXT
content=
ELEMENT bar:Something
TEXT
content=
ELEMENT foo:Something
TEXT
content=
ELEMENT baz:Something
TEXT
content=
TEXT
content=
TEXT
content=
ELEMENT foo:Something
TEXT
content=
ELEMENT baz:Something
TEXT
content=
TEXT
content=
ELEMENT baz:Something
TEXT
content=
TEXT
content=
TEXT
content=
TEXT
content=
As you can see, we have nodes instead of namespace in the result nodes
set. I looked at
the xpath.c file and found following comment (that probably explains the
above result):
/**
* xmlXPathNodeSetDupNs:
* @node: the parent node of the namespace XPath node
* @ns: the libxml namespace declaration node.
*
* Namespace node in libxml don't match the XPath semantic. In a
node set
* the namespace nodes are duplicated and the next pointer is set to the
* parent node in the XPath semantic.
*
* Returns the newly created object.
*/
My question is: what was the reason for this special namespace nodes
processing and can
we process namespace nodes in the same way as all other nodes in xpath
evaluation?
Aleksey.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]