[jdom-interest] JDOM && Jaxen

bob mcwhirter bob at werken.com
Thu Aug 2 07:43:40 PDT 2001


> >	count(//namespace::*)
> >
> >should return 2, but for JDOM, only returns 1.
> >
> 
> No, it wouldn't. It should return 0 because * doesn't match
> namespace nodes, and because namespaces will not be found along the
> descendant-or-self axis implied by //.

Expanded, that expression is

	/descendant-or-self::node()/namespace::*

fwiw, //namespace::* is the expression specified by the C14N spec
for selecting the namespace nodes of a document:

	(//. | //@* | //namespace::*)[not(self::comment())]

			or (without comments)

	(//. | //@* | //namespace::*)

Which basically selectes all Element nodes, and THEN selects all namespace
nodes hanging from those element nodes.  It's a 2-step xpath.

> More importantly, you seem to be confused about what the namespace
> axis in XPath actually does. It counts namespace NODES, not namespace
> declarations. From Section 2.2 of the XPath spec:
> 
> the namespace axis contains the namespace nodes of the context node;
> the axis will be empty unless the context node is an element

Right, no confusion there, excapt as to what exactly is
a 'namespace node'.

> and from section 5.4:
> 
> Each element has an associated set of namespace nodes, one for each
> distinct namespace prefix that is in scope for the element (including
> the xml prefix, which is implicitly declared by the XML Namespaces
> Recommendation [XML Names]) and one for the default namespace if one
> is in scope for the element. The element is the parent of each of these
> namespace nodes; however, a namespace node is not a child of its parent
> element. Elements never share namespace nodes: if one element node is
> not the same node as another element node, then none of the namespace
> nodes of the one element node will be the same node as the namespace
> nodes of another element node. This means that an element will have a
> namespace node:

Ahh, here's where I went wrong.  Thanks for pointing this out.
So, I *am* actually looking just for Namespace objects that are
in scope at a particular point.

> JDOM is actually quite close to this model. I don't think flyweights
> really get in the way of doing proper support of the namespace axis in
> XPath. They would only be a problem for the most naive implementation,
> which wouldn't really work anyway.

I'll admit my implementation is/was incorrect, and quite possibly 
naive, due to a mis-understanding of the XPath spec.

Ignore all previous comments until I re-evaluate what I'm supposed
to be doing with the namespace:: axis.

Thanks for humoring me (and whacking me with the big ol' RTFM
stick. :)

	-bob






More information about the jdom-interest mailing list