[jdom-interest] Element.getDocument() ?

Joerg joerg at freiheit.com
Thu Aug 31 07:29:19 PDT 2000


So, just to see whether I got the point (I yust gave up to look through the XPath API in the
contrib section completely :-), I have to take a closer look soon). When you call e.g.
some_element.getItemByXPath( "/comment()") or something like that, you have no way to
determine in which Document the node is. Or you have a preconstructed XPath object, but you
don't want to reference a Document in there, because it is reusable and only dependent of the
xpath String.
But you can give it to the apply method (I'm not really sure whether this method is called
from the application). Often the application, which calls the XPath method does have a
reference of the Document object anyway. So it should be at least also possible to provide
XPath with the document, in case you already have it. And you have to think about, that even
when the Document is only stored in the root Element, it at least increases the memory
footprint of all Elements (if this matters at all).

Joerg

bob wrote:

>         /comment()
>
>         Given any Element from the doc, get any Comment node
>         that is a peer of the root element.  Not owned by the
>         root element, but at the same level as it.
>
>         XPaths deal strictly in terms of Elements.  (In fact,
>         the spec doesn't mention Document at all, but does
>         include a concept of an Element which holds the root
>         element, and Comments and ProcInstrs which are
>         siblings of the root element.)
>
>         Right now, an XPath maintains no state related to
>         the Element being walked.  Which is good.  Cache
>         an XPath from an XSLT stylesheet, annd apply to multiple
>         different souce .xml documents.
>
>                 -bob
>
> On Thu, 31 Aug 2000, Joerg wrote:
>
> > Can you explain it to me, what is the problem in the XPath implementation where you need
> > the method? A recursive getParent() seems also not to be very efficient. Maybe it is
> > possible to keep the owner Document somewhere in the XPath classes or keep track of it,
> > by passing it seperately to the necessary functions.
> >
> > Joerg
> >
> > bob wrote:
> >
> > > Probably just recursively getParent() until isRootElement(),
> > > and hold a reference to the Document there.  Maybe.
> > >
> > >         -bob
> > >
> > > On Thu, 31 Aug 2000, Joerg wrote:
> > >
> > > > How do you want to do that? Do you want to put a referencce to a Document in every
> > > > Element? When you do it like this, you have to update all Elemets when you copy a
> > > > subtree from one Document to another. This would be the same "ownerDocument" -
> > > > "cloneNode" problem like in DOM.
> > > >
> > > > Joerg
> > > >
> > > >
> > > > bob wrote:
> > > >
> > > > > > > Currently, there appears to be no way to obtain the Document
> > > > > > > which owns a particular Element.
> > > > > >
> > > > > > I'm OK with this, but I don't have the time to make the changes. There
> > > > > > would need to be changes in Element.java, PartialList.java, and
> > > > > > Document.java, as far as I can tell.
> > > > > >
> > > > > > Wanna do them, Bob?
> > > > >
> > > > > Sure.  Though, I'm offline until next Wednesday.  So, I'll submit
> > > > > a patch mid-to-late next week.
> > > > >
> > > > >         -bob
> > > > >
> > > > > _______________________________________________
> > > > > To control your jdom-interest membership:
> > > > > http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> > > >
> > > >
> >
> >
> >
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



--
<?xml version="1.0" standalone="no" encoding="ISO-8859-1"?>
<businesscard>
  <bookmarks>
    <bookmark> http://www.google.com </bookmark>
    <bookmark> http://www.gnu.org </bookmark>
    <bookmark> http://java.apache.org </bookmark>
    <bookmark> http://www.w3.org </bookmark>
    <bookmark> http://www-db.stanford.edu/lore </bookmark>
  </bookmarks>
  <sender>
    <firstname> Jörg </firstname>
    <name> Kirchhof </name>
    <title> Dipl.-Ing. </title>
    <email> joerg at freiheit.com </email>
    <phone> +49-40-890584-14 </phone>
  </sender>
  <company>
    <name> freiheit.com Technologieberatung GmbH </name>
    <address> Theodorstraße 42-90 </address>
    <zip> 22761 </zip>
    <city> Hamburg </city>
    <country> Germany </country>
    <phone> +49-40-890584-0 </phone>
    <fax> +49-40-890584-20 </fax>
    <www> http://www.freiheit.com </www>
  </company>
</businesscard>





More information about the jdom-interest mailing list