[jdom-interest] XML tree traversing
stm at prosoft.sk
Tue Jan 2 00:58:43 PST 2001
Here is what I want to do:
I want to improve my framework for Java Servlet
application development - I have used standard
java.util.Properties to store application
properties, but now I want to replace it with
some XML-based solution.
To centralize property management, all applications
derived from my framework have the method
void onPropertyChange(String property_name, String value, Number
which is called anytime the application property is changed.
Therefore, when application (and its XML property file) is loaded
I need to traverse whole XML tree to trigger onPropertyMethod
for each XML node (element or element's attribute).
I know that I can use getChildren().iterator(), but I wanted
to avoid "(Element) iterator.next()" conversion
(am I not lazy ? ;-) and also memory overhead (that would
be true only if internal representation in JDOM has changed
e.g. there is no "protected List content;" but something like
"protected Node firstChild;").
Anyway, it is not causing me to much pain :-), I can traverse XML tree
with JDOM pretty well, but I've asked this question because it concerns more
general software design and I wanted to know your opinion.
What I'm really missing in JDOM is some minimal support for XPath.
As you see, my onPropertyChange method has argument property_name,
and I think the best option would be XPath.
Therefore when traversing XML tree I need method that gives me
XPath of the current node (element or element's attribute - in
my case both can carry application property).
I also need method for obtaining node (again element or element's
attribute) for given XPath.
Are you or somebody else working on this issue ?
> -----Original Message-----
> From: Jason Hunter [mailto:jhunter at collab.net]
> Sent: Thursday, December 28, 2000 7:27 PM
> To: Mores Stanislav
> Cc: jdom-interest at jdom.org
> Subject: Re: [jdom-interest] XML tree traversing
> > Mores Stanislav wrote:
> > Hi,
> > I wondered why not to have simpler mean of XML tree traversing,
> > by defining the following methods:
> > Element getFirstChild(); - returns first
> child element
> > or null
> > Element getNextSibling(); - returns next
> sibling element
> > or null
> > and possibly:
> > Element getPrevSibling();
> Might want to try getChildren().iterator(). Then you get the standard
> Java Iterator behavior. Or getMixedContent().iterator() if
> you want all
> mixed content.
> > That would be more easier to use than getChildren(),
> > with no memory overhead (no List allocation),
> You still have to allocate some data structure to track where you are
> and keep track of modifications you might make. It's best if
> we use the
> standard Java Iterator data structure for that.
> > especially when traversing the whole tree, which is my
> > case ( I need to process each node in the tree).
> If you want to process each item in the tree, you'd be better off
> arguing for a document iterator/walker/traverser. I'm trying
> to see if
> we have a compelling use case for that (both to justify adding it, and
> to make sure a solution solves those issues), so please, if you could,
> explain your use case.
> To control your jdom-interest membership:
uraddr at yourhost.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the jdom-interest