[jdom-interest] Element Reference from Attribute

James Strachan james at metastuff.com
Wed Nov 22 02:28:08 PST 2000


----- Original Message -----
From: "Patrick Dowler" <Patrick.Dowler at nrc.ca>
> On Tue, 21 Nov 2000, Louis Tribble wrote:
> In a singly-linked version, you could write a Builder that tried to share
> references to Attributes. In some cases, this could give a great advantage
> in memory consumption. For example, say I have a dataset written as:
>
> <table>
>   <row>
>       <cell width=20>narrow</cell>
>       <cell width=40>wide</cell>
>   </row>
>   <row>
>      <cell width=20>narrow</cell>
>       <cell width=40>wide</cell>
>   </row>
>   ...
> </rable>
>
> You could have only two distinct attributes: Attribute("width",20) and
> Attribute("width",40). Normally, a table with 10k rows has 20k attribute
> objects when it could have 2. If I was wriitng a servlet that processing
> query results into an HTML table, I might want to make this sort of
> optimization. If I am writing a client GUI which reads a large table and
> displays it, I would do the same with 10k objects that were effectively
> the same.

Exactly!

This technique is particularly useful when building singly linked JDOM trees
'by hand'. You could use static final (preferably immutable) Attribute
instances which can then be added to many Elements in many documents without
creating new Attribute instances. This can have a big peformance benefit -
particularly as a lot of Attribute values are often enumerations (in the DTD
sense) so a single attribute instance can be shared for each value of an
enumeration.

This kind of optimisation (similar to the effect of String.intern()) should
not be discounted, just because a subset of the XML population want to do
full upward XPath navigation.

Remember that downward XPath navigation can still be supported with a singly
linked tree and a singly linked tree can easily mutated to doubly linked
whenever it needs to be.

One example thats been sited on the list is that an XPath expression which
selects a set of Attributes - the user may then want to iterate through the
Attributes asking for their parent. Well there's nothing to stop
doubly-linked Attributes being returned from an XPath expression on a singly
linked tree.

J.

James Strachan
=============
email: james at metastuff.com
web: http://www.metastuff.com



If you are not the addressee of this confidential e-mail and any
attachments, please delete it and inform the sender; unauthorised
redistribution or publication is prohibited. Views expressed are those of
the author and do not necessarily represent those of Citria Limited.



More information about the jdom-interest mailing list