[jdom-interest] Element Reference from Attribute

Patrick Dowler Patrick.Dowler at nrc.ca
Fri Nov 17 10:36:05 PST 2000


On Fri, 17 Nov 2000, Jason Hunter wrote:
> bob mcwhirter wrote:
> > 
> > > That is, how is it that one can be navigating from an Attribute 
> > > with no knowledge of the Element with said Attribute?
> > 
> > Using my XPath library, for one.
> 
> Yep, Bob's killer use case is why giving attribs knowledge of their
> parent element is a TODO item.

I guess I'm just dense. Does XPath actually require that one can get Elements 
after searching for Attributes? It still seems to me that this is convenience
since XPath is supposedly returning a List of Elements or Attributes and
after that it is user-code that wants this feature, not XPath per se. Just
because user-code wants to use

	XPath("/foo/bar/baz/@goober")   // goober attributes

instead of 

	XPath("/foo/bar/baz/@goober/..")  // parents of goobers ?

or

	XPath("/foo/bar/baz[@goober]")   // elements with goober attributes?

If Attribute does not have a getParent method, then people won't be using
the first to find elements with "goober"s. Since the parent of an attribute is an
Element, the other two would always return the same elements, yes?

So, it is a use case to get a list of attributes and then want to get the
parent elements, but you can do this without getParent if you use an
XPath which says what you actually want. If you want both the Attribute
and its parent Element, getting the parent Element is sufficient and we
are still only singly linked (wrt Attributes).

Unless the first XPath must enable access to the Element (indirectly)
then I still don't see the requirement.... 

-- 

Patrick Dowler
Canadian Astronomy Data Centre




More information about the jdom-interest mailing list