<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>This works great. Though i tried to figure out what
is happening but can't quite get it. Could u maybe explain what happens here(or
point me to a site which explains it), how is the tree like structure made? And
why doesn't it work in my piece of code? Als i wonder if it would be easy to
also list the attributes and labels?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Kind regards, </FONT></DIV>
<DIV><FONT face=Arial size=2> Joachim Albers.</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=Phill_Perryman@Mitel.COM
href="mailto:Phill_Perryman@Mitel.COM">Phill_Perryman@Mitel.COM</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=jalbers@cs.uu.nl
href="mailto:jalbers@cs.uu.nl">J. Albers</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=jdom-interest@jdom.org
href="mailto:jdom-interest@jdom.org">jdom-interest@jdom.org</A> ; <A
title=jdom-interest-admin@jdom.org
href="mailto:jdom-interest-admin@jdom.org">jdom-interest-admin@jdom.org</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Friday, January 23, 2004 3:31
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [jdom-interest] JTree</DIV>
<DIV><BR></DIV><BR><FONT face=sans-serif size=2>I had the following from one
of my extended element (Elementx) classes, you can replace this with the root
note for the tree</FONT> <BR><BR><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2 size=2><TT>/**</TT></FONT> <BR><FONT
size=2><TT> </TT></FONT><FONT color=#4040c2
size=2><TT>*</TT></FONT><FONT size=2><TT> </TT></FONT><FONT color=#4040c2
size=2><TT>Returns</TT></FONT><FONT size=2><TT> </TT></FONT><FONT
color=#4040c2 size=2><TT>a</TT></FONT><FONT size=2><TT> </TT></FONT><FONT
color=#4040c2 size=2><TT>DefaultMutableTreeNode</TT></FONT><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2 size=2><TT>for</TT></FONT><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2 size=2><TT>use</TT></FONT><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2 size=2><TT>in</TT></FONT><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2 size=2><TT>a</TT></FONT><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2 size=2><TT>JTree</TT></FONT><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2 size=2><TT>which</TT></FONT> <BR><FONT
size=2><TT> </TT></FONT><FONT color=#4040c2
size=2><TT>*</TT></FONT><FONT size=2><TT> </TT></FONT><FONT color=#4040c2
size=2><TT>represents</TT></FONT><FONT size=2><TT> </TT></FONT><FONT
color=#4040c2 size=2><TT>the</TT></FONT><FONT size=2><TT> </TT></FONT><FONT
color=#4040c2 size=2><TT>element</TT></FONT> <BR><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2
size=2><TT>*</TT></FONT><FONT size=2><TT> </TT></FONT><FONT color=#71b2cf
size=2><TT><B>@return</B></TT></FONT><FONT size=2><TT> </TT></FONT><FONT
color=#4040c2 size=2><TT>DefaultMutableTreeNode</TT></FONT> <BR><FONT
size=2><TT> </TT></FONT><FONT color=#4040c2
size=2><TT>*/</TT></FONT> <BR><FONT size=2><TT>
</TT></FONT><FONT color=#820040 size=2><TT>public</TT></FONT><FONT size=2><TT>
DefaultMutableTreeNode getTreeNode() {</TT></FONT> <BR><FONT size=2><TT>
DefaultMutableTreeNode
treeNode = </TT></FONT><FONT color=#820040 size=2><TT>new</TT></FONT><FONT
size=2><TT> DefaultMutableTreeNode(</TT></FONT><FONT color=#820040
size=2><TT>this</TT></FONT><FONT size=2><TT>);</TT></FONT> <BR><FONT
size=2><TT>
addChildren(treeNode, </TT></FONT><FONT color=#820040
size=2><TT>this</TT></FONT><FONT size=2><TT>);</TT></FONT> <BR><FONT
size=2><TT>
</TT></FONT><FONT color=#820040 size=2><TT>return</TT></FONT><FONT size=2><TT>
treeNode;</TT></FONT> <BR><FONT size=2><TT>
}</TT></FONT> <BR><BR><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2 size=2><TT>/**</TT></FONT> <BR><FONT
size=2><TT> </TT></FONT><FONT color=#4040c2
size=2><TT>*</TT></FONT><FONT size=2><TT> </TT></FONT><FONT color=#4040c2
size=2><TT>Internal</TT></FONT><FONT size=2><TT> </TT></FONT><FONT
color=#4040c2 size=2><TT>function</TT></FONT><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2 size=2><TT>to</TT></FONT><FONT size=2><TT>
</TT></FONT><FONT color=#4040c2 size=2><TT>support</TT></FONT><FONT
size=2><TT> </TT></FONT><FONT color=#4040c2 size=2><TT>get</TT></FONT><FONT
size=2><TT> </TT></FONT><FONT color=#4040c2 size=2><TT>tree</TT></FONT><FONT
size=2><TT> </TT></FONT><FONT color=#4040c2 size=2><TT>node</TT></FONT>
<BR><FONT size=2><TT> </TT></FONT><FONT
color=#4040c2 size=2><TT>*/</TT></FONT> <BR><FONT size=2><TT>
</TT></FONT><FONT color=#820040
size=2><TT>private</TT></FONT><FONT size=2><TT> </TT></FONT><FONT
color=#820040 size=2><TT>static</TT></FONT><FONT size=2><TT> </TT></FONT><FONT
color=#820040 size=2><TT>void</TT></FONT><FONT size=2><TT>
addChildren(DefaultMutableTreeNode tn,Elementx element) {</TT></FONT>
<BR><FONT size=2><TT>
DefaultMutableTreeNode node;</TT></FONT> <BR><FONT size=2><TT>
List children =
element.getChildren();</TT></FONT> <BR><FONT size=2><TT>
Iterator it =
children.iterator();</TT></FONT> <BR><FONT size=2><TT>
</TT></FONT><FONT color=#820040
size=2><TT>while</TT></FONT><FONT size=2><TT> (it.hasNext()) {</TT></FONT>
<BR><FONT size=2><TT>
Elementx child = (Elementx) it.next();</TT></FONT>
<BR><FONT size=2><TT>
node = </TT></FONT><FONT color=#820040
size=2><TT>new</TT></FONT><FONT size=2><TT>
DefaultMutableTreeNode(child);</TT></FONT> <BR><FONT size=2><TT>
tn.add(node);</TT></FONT> <BR><FONT size=2><TT>
addChildren(node,
child);</TT></FONT> <BR><FONT size=2><TT>
};</TT></FONT> <BR><FONT size=2><TT>
}</TT></FONT><FONT face=sans-serif size=2><BR><BR>/Phill<BR>IS Dept,
Software Engineer.<BR>phill_perryman@mitel.com<BR>http://www.mitel.com<BR>Tel:
+44 1291 436023</FONT> <BR><BR><BR>
<TABLE width="100%">
<TBODY>
<TR vAlign=top>
<TD>
<TD><FONT face=sans-serif size=1><B>"J. Albers"
<jalbers@cs.uu.nl></B></FONT> <BR><FONT face=sans-serif
size=1>Sent by: jdom-interest-admin@jdom.org</FONT>
<P><FONT face=sans-serif size=1>23/01/2004 14:14</FONT> <BR></P>
<TD><FONT face=Arial size=1> </FONT><BR><FONT
face=sans-serif size=1> To:
<jdom-interest@jdom.org></FONT> <BR><FONT
face=sans-serif size=1> cc:
</FONT> <BR><FONT face=sans-serif size=1>
Subject: [jdom-interest]
JTree</FONT></TR></TBODY></TABLE><BR><BR><BR><FONT face="Courier New"
size=2>Hey,<BR><BR>I want to list an XML file into a JTree, so that it
has the same hierarchy<BR>as the original document. The code now does<BR>only
list all elements in one row, but no nesting. Does anyone know how i<BR>can
get the elements to be outputted with the same<BR>nesting as in the XML
file?<BR><BR>Grtz, Joachim.<BR><BR><BR>private static void
listElements(Element e)<BR>{<BR> int depth =
0;<BR> DefaultMutableTreeNode newelements =
null;<BR> DefaultMutableTreeNode newchildren =
null;<BR> System.out.println("*Element, name:" + e.getName() +<BR>
", text:" + e.getText()) ;<BR> newelements = new
DefaultMutableTreeNode(e.getName());<BR> Main.elements.add(newelements);<BR> if(e.getText()
!= "")<BR> {<BR> newchildren = new
DefaultMutableTreeNode(e.getText());<BR>
Main.elements.add(newchildren);<BR> }<BR><BR><BR> //List all
attributes<BR> List as = e.getAttributes();<BR> for (Iterator i =
as.iterator();i.hasNext();)<BR> {<BR> depth++;<BR> Attribute
a = (Attribute)i.next();<BR> System.out.println("*Attribute, name:" +
a.getName() +<BR> ", value:" + a.getValue())
;<BR> }<BR><BR> //List all children<BR> List c =
e.getChildren();<BR><BR> for (Iterator i =
c.iterator();i.hasNext();)<BR> {<BR> depth++;<BR>
System.out.println("depth = "+depth);<BR> Element n =
(Element)i.next();<BR>
listElements(n);<BR> }<BR>}<BR><BR>_______________________________________________<BR>To
control your jdom-interest
membership:<BR>http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com<BR></FONT><BR><BR></BLOCKQUOTE></BODY></HTML>