<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-2">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2650.12">
<TITLE>RE: [jdom-interest] XML tree traversing</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Here is what I want to do:</FONT>
</P>
<P><FONT SIZE=2>I want to improve my framework for Java Servlet</FONT>
<BR><FONT SIZE=2>application development - I have used standard </FONT>
<BR><FONT SIZE=2>java.util.Properties to store application </FONT>
<BR><FONT SIZE=2>properties, but now I want to replace it with</FONT>
<BR><FONT SIZE=2>some XML-based solution.</FONT>
</P>
<P><FONT SIZE=2>To centralize property management, all applications</FONT>
<BR><FONT SIZE=2>derived from my framework have the method</FONT>
<BR><FONT SIZE=2> void onPropertyChange(String property_name, String value, Number num_value);</FONT>
<BR><FONT SIZE=2>which is called anytime the application property is changed.</FONT>
</P>
<P><FONT SIZE=2>Therefore, when application (and its XML property file) is loaded</FONT>
<BR><FONT SIZE=2>I need to traverse whole XML tree to trigger onPropertyMethod</FONT>
<BR><FONT SIZE=2>for each XML node (element or element's attribute).</FONT>
<BR><FONT SIZE=2>I know that I can use getChildren().iterator(), but I wanted</FONT>
<BR><FONT SIZE=2>to avoid "(Element) iterator.next()" conversion </FONT>
<BR><FONT SIZE=2>(am I not lazy ? ;-) and also memory overhead (that would </FONT>
<BR><FONT SIZE=2>be true only if internal representation in JDOM has changed</FONT>
<BR><FONT SIZE=2>e.g. there is no "protected List content;" but something like</FONT>
<BR><FONT SIZE=2>"protected Node firstChild;").</FONT>
<BR><FONT SIZE=2>Anyway, it is not causing me to much pain :-), I can traverse XML tree </FONT>
<BR><FONT SIZE=2>with JDOM pretty well, but I've asked this question because it concerns more</FONT>
<BR><FONT SIZE=2>general software design and I wanted to know your opinion.</FONT>
</P>
<P><FONT SIZE=2>What I'm really missing in JDOM is some minimal support for XPath.</FONT>
<BR><FONT SIZE=2>As you see, my onPropertyChange method has argument property_name,</FONT>
<BR><FONT SIZE=2>and I think the best option would be XPath. </FONT>
<BR><FONT SIZE=2>Therefore when traversing XML tree I need method that gives me</FONT>
<BR><FONT SIZE=2>XPath of the current node (element or element's attribute - in </FONT>
<BR><FONT SIZE=2>my case both can carry application property).</FONT>
<BR><FONT SIZE=2>I also need method for obtaining node (again element or element's </FONT>
<BR><FONT SIZE=2>attribute) for given XPath.</FONT>
<BR><FONT SIZE=2>Are you or somebody else working on this issue ?</FONT>
</P>
<P><FONT SIZE=2>Thanks.</FONT>
</P>
<P> <FONT SIZE=2>Stm.</FONT>
</P>
<BR>
<BR>
<BR>
<BR>
<P><FONT SIZE=2>> -----Original Message-----</FONT>
<BR><FONT SIZE=2>> From: Jason Hunter [<A HREF="mailto:jhunter@collab.net">mailto:jhunter@collab.net</A>]</FONT>
<BR><FONT SIZE=2>> Sent: Thursday, December 28, 2000 7:27 PM</FONT>
<BR><FONT SIZE=2>> To: Mores Stanislav</FONT>
<BR><FONT SIZE=2>> Cc: jdom-interest@jdom.org</FONT>
<BR><FONT SIZE=2>> Subject: Re: [jdom-interest] XML tree traversing</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> > Mores Stanislav wrote:</FONT>
<BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > Hi,</FONT>
<BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > I wondered why not to have simpler mean of XML tree traversing,</FONT>
<BR><FONT SIZE=2>> > by defining the following methods:</FONT>
<BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > Element getFirstChild(); - returns first </FONT>
<BR><FONT SIZE=2>> child element</FONT>
<BR><FONT SIZE=2>> > or null</FONT>
<BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > Element getNextSibling(); - returns next </FONT>
<BR><FONT SIZE=2>> sibling element</FONT>
<BR><FONT SIZE=2>> > or null</FONT>
<BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > and possibly:</FONT>
<BR><FONT SIZE=2>> > Element getPrevSibling();</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Might want to try getChildren().iterator(). Then you get the standard</FONT>
<BR><FONT SIZE=2>> Java Iterator behavior. Or getMixedContent().iterator() if </FONT>
<BR><FONT SIZE=2>> you want all</FONT>
<BR><FONT SIZE=2>> mixed content.</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> > That would be more easier to use than getChildren(),</FONT>
<BR><FONT SIZE=2>> > with no memory overhead (no List allocation),</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> You still have to allocate some data structure to track where you are</FONT>
<BR><FONT SIZE=2>> and keep track of modifications you might make. It's best if </FONT>
<BR><FONT SIZE=2>> we use the</FONT>
<BR><FONT SIZE=2>> standard Java Iterator data structure for that.</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> > especially when traversing the whole tree, which is my</FONT>
<BR><FONT SIZE=2>> > case ( I need to process each node in the tree).</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> If you want to process each item in the tree, you'd be better off</FONT>
<BR><FONT SIZE=2>> arguing for a document iterator/walker/traverser. I'm trying </FONT>
<BR><FONT SIZE=2>> to see if</FONT>
<BR><FONT SIZE=2>> we have a compelling use case for that (both to justify adding it, and</FONT>
<BR><FONT SIZE=2>> to make sure a solution solves those issues), so please, if you could,</FONT>
<BR><FONT SIZE=2>> explain your use case.</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> -jh-</FONT>
<BR><FONT SIZE=2>> _______________________________________________</FONT>
<BR><FONT SIZE=2>> To control your jdom-interest membership:</FONT>
<BR><FONT SIZE=2>> <A HREF="http://lists.denveronline.net/mailman/options/jdom-interest/yo" TARGET="_blank">http://lists.denveronline.net/mailman/options/jdom-interest/yo</A></FONT>
<BR><FONT SIZE=2>uraddr@yourhost.com</FONT>
</P>
</BODY>
</HTML>