[jdom-interest] JTree

J. Albers jalbers at cs.uu.nl
Tue Jan 27 06:02:56 PST 2004

Ahh, that makes sense, i think i get most of it now. What i'm trying to make is some application that takes 2 XML files and tries to fuse them together semi-automatically. So the elemnts that are the same get fused right away, and then the rest of the elements from the files is listed, and one can select the elements that are the same but have different names in different files and fuse them.

I'm quite new at JDOM, so maybe someone of u has some thoughts on this idea and can give me some tips, cause at the moment i don't see where i can start with comparing the elements from 2 XML documents.

Kind regards,
    Joachim Albers
  ----- Original Message ----- 
  From: Phill_Perryman at Mitel.COM 
  To: J. Albers 
  Cc: jdom-interest at jdom.org 
  Sent: Tuesday, January 27, 2004 2: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/20040127/7a5dd7a4/attachment.htm

More information about the jdom-interest mailing list