[jdom-interest] JDOM && Jaxen

Elliotte Rusty Harold elharo at metalab.unc.edu
Thu Aug 2 04:39:32 PDT 2001


At 3:13 PM -0400 8/1/01, bob mcwhirter wrote:
>On Wed, 1 Aug 2001, Jason Hunter wrote:
>
>> bob mcwhirter wrote:
>> > 
>> > Yah, even without getParent(), though, not using flyweights on the
>> > Namespaces would help.
>> 
>> Really, why?
>
><foo>
>	<bar xmlns:cheese="http://cheese.org/"/>
>	<bar xmlns:cheese="http://cheese.org/"/>
></foo>
>
>This document has 2 namespace nodes, but that's represented
>in JDOM as only a single Namespace object, due to fly-weighting.
>
>Thus, this xpath
>
>	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 //.

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

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:

 for every attribute on the element whose name starts with xmlns:;
 for every attribute on an ancestor element whose name starts xmlns: unless the element itself or a nearer ancestor redeclares the prefix;
 for an xmlns attribute, if the element or some ancestor has an xmlns attribute, and the value of the xmlns attribute for the nearest such element is non-empty

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. 
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+ 
|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
|              http://www.ibiblio.org/xml/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      | 
|  Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/     |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list