[jdom-interest] JTree

Ed Maher ed.maher at euromainbt.co.uk
Wed Jan 28 06:48:21 PST 2004

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.

  * Creates an element
 public Element element(String name, String uri) {        
  return new Elementx(name,uri);
  * Creates an element
 public Element element(String name, String prefix, String uri) {        
  return new Elementx(name,prefix,uri);
  * Creates an element
    public Element element(String name, Namespace namespace) {        
  return new Elementx(name, namespace);

  ----- Original Message ----- 
  From: Ed Maher 
  To: J. Albers ; Phill_Perryman at Mitel.COM 
  Cc: jdom-interest at jdom.org 
  Sent: Wednesday, January 28, 2004 2:12 PM
  Subject: Re: [jdom-interest] JTree


  I also have an interest in xml->JTree linking, so I tried the sample code, but unfortunately, I am getting a class cast
  exception in SAXHandlerx::endElement() on the line...

  Elementx e = (Elementx) currentElement;

  but I only get this when loading a document from file.

  Surely this could only work if we had actually created an Elementx to populate 'currentElement', I don't see where that is done.

  I am particularly confused, as the hard-coded test-data works, file reading does not.


    ----- Original Message ----- 
    From: Phill_Perryman at Mitel.COM 
    To: J. Albers 
    Cc: jdom-interest at jdom.org 
    Sent: Tuesday, January 27, 2004 1:06 PM
    Subject: Re: [jdom-interest] JTree

    >>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? 

    I don't know of any site which explains it. The underlying principle is "Recursion". 

    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. 

    Don't know if I can explain it much better. 

    for a document like 

    root calls addChildren 
       add Children adds a to root and then calls add children (to a) 
            add children adds x to a then calls add children (to x) 
                add children adds z to x 
                exit method 
            add children adds y to a 
            exit method 
      add children adds b to root 
      exit method 
    end calling sequence 

    The Java I base my development on is attached if it is any use. 
    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 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20040128/6029c5e5/attachment.htm

More information about the jdom-interest mailing list