[jdom-interest] getting the top

Mark Hortman mark.hortman at jcafeinc.com
Thu Dec 19 08:36:27 PST 2002


First of all, look into using xpath to do this, eliminates loops, and makes
jdom traversal quite easy, look into jaxen for this.

XPath xpAttribute = new XPath("/root/sequence/*[@myAttribute='X']");
Element elementWithMyAttributeEqualsX =
(Element)xpAttribute.selectSingleNode(myDocument);


Second, if you want to use a loop, I assume you used code like this:

List listSequenceChildren = sequence.getChildren();
Iterator iterSequence = listSequenceChilden.iterator();
while (iterSequence.hasNext()){
   Element sequenceChild = (Element)iterSequence.next();
   if (sequenceChild.getAttribute("blah")== null){
       // do whatever..
   }
}

You would have to get another iterator from your list to go back through.
But, really use xpath.

-----Original Message-----
From: Antonello Dell'Armi [mailto:A.Dellarmi at ELIS.ORG]
Sent: Thursday, December 19, 2002 10:01 AM
To: Mark Hortman
Cc: jdom-interest at jdom.org
Subject: R: [jdom-interest] getting the top


Hi Mark,i have :
root
sequence  
	a/
	b/
	c/
	d/	
	e/
	f/
/sequence
/root

My situation is this:
i'm looking for an attribute between the elments a - f and at the end of the
while loop(i arrived at f element) that do this i would like to search
another attribute and so i have to start from element a.

BRGS
Antonello



More information about the jdom-interest mailing list