<!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>OK, problem solved - if anyone is interested in
using this code, you should also override the other Element methods in the
JDOMFactoryx to ensure that non-trivial elements are processed
correctly.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> /**<BR> * Creates an element<BR>
*/<BR> public Element element(String name, String uri)
{ <BR> return new
Elementx(name,uri);<BR> }<BR> /**<BR> * Creates an
element<BR> */<BR> public Element element(String name, String prefix,
String uri) { <BR> return
new Elementx(name,prefix,uri);<BR> }<BR> /**<BR> *
Creates an element<BR> */<BR> public Element
element(String name, Namespace namespace)
{ <BR> return new
Elementx(name, namespace);<BR> }<BR>
<BR> </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<BLOCKQUOTE dir=ltr
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=ed.maher@euromainbt.co.uk href="mailto:ed.maher@euromainbt.co.uk">Ed
Maher</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=jalbers@twc.sshunet.nl
href="mailto:jalbers@twc.sshunet.nl">J. Albers</A> ; <A
title=Phill_Perryman@Mitel.COM
href="mailto:Phill_Perryman@Mitel.COM">Phill_Perryman@Mitel.COM</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> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, January 28, 2004 2:12
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [jdom-interest] JTree</DIV>
<DIV><BR></DIV>
<DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I also have an interest in xml->JTree linking,
so I tried the sample code, but unfortunately, I am getting a class
cast</FONT></DIV>
<DIV><FONT face=Arial size=2>exception in SAXHandlerx::endElement() on the
line...</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Elementx e = (Elementx)
currentElement;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>but I only get this when loading a document from
file.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Surely this could only work if we had actually
created an Elementx to populate 'currentElement', I don't see where that is
done.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I am particularly confused, as the hard-coded
test-data works, file reading does not.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Ed.</FONT></DIV>
<DIV><FONT face=Arial size=2></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@twc.sshunet.nl
href="mailto:jalbers@twc.sshunet.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> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, January 27, 2004 1:06
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [jdom-interest]
JTree</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV><BR><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>
<BR><BR><FONT face=sans-serif size=2>I don't know of any site which explains
it. The underlying principle is "Recursion".</FONT> <BR><BR><FONT
face=sans-serif size=2>You start with the root node and then call a method
to add the children, the method that adds a child calls a method (actually
itself) to add its own children (which calls itself again to add its
children, recursively) before moving onto the next element. Trying to work
out what level you are on and remember where you are in the tree hierarchy
is a nightmare to do when trying to represent it at a flat level. Because
the variables in the method call are local to it you can nest the calls
without having to keep track of where you are as you get one add children
method call per nested element.</FONT> <BR><BR><FONT face=sans-serif
size=2>Don't know if I can explain it much better.</FONT> <BR><BR><FONT
face=sans-serif size=2>for a document like</FONT> <BR><FONT face=sans-serif
size=2><root></FONT> <BR><FONT face=sans-serif size=2>
<a></FONT> <BR><FONT face=sans-serif size=2>
<x></FONT> <BR><FONT face=sans-serif size=2>
<z/></FONT> <BR><FONT face=sans-serif size=2>
</x></FONT> <BR><FONT face=sans-serif size=2>
<y/></FONT> <BR><FONT face=sans-serif size=2> </a></FONT>
<BR><FONT face=sans-serif size=2> <b/></FONT> <BR><FONT
face=sans-serif size=2></root></FONT> <BR><BR><FONT face=sans-serif
size=2>root calls addChildren</FONT> <BR><FONT face=sans-serif size=2>
add Children adds a to root and then calls add children (to a)</FONT>
<BR><FONT face=sans-serif size=2> add children
adds x to a then calls add children (to x)</FONT> <BR><FONT face=sans-serif
size=2> add children adds z to
x</FONT> <BR><FONT face=sans-serif size=2>
exit method</FONT> <BR><FONT face=sans-serif size=2>
add children adds y to a</FONT> <BR><FONT face=sans-serif
size=2> exit method</FONT> <BR><FONT
face=sans-serif size=2> add children adds b to root</FONT> <BR><FONT
face=sans-serif size=2> exit method</FONT> <BR><FONT face=sans-serif
size=2>end calling sequence</FONT> <BR><BR><FONT face=sans-serif size=2>The
Java I base my development on is attached if it is any use.</FONT> <BR><FONT
face=sans-serif size=2>The tree note uses the user objects toString method
to display the tree node. That is why I use an extended Element (Elementx)
class so that I can override the toString method in Element to provide the
representation in the tree that I want. There is a simple document viewer
that shows the JTree formatting</FONT>
<BR><BR><BR></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>