Hello,
short version: Is there a possibility using jdom to get the "following-sibling" of an element.
long version: Assume i've got the following xml file:
<party datum="31.12.01">
<gast>
<person>
<name>Albert Angsthase</name>
</person>
<getraenk>Wein</getraenk>
</gast>
<gast>
<person>
<name>Martina Mutig</name>
</person>
<getraenk>Apfelsaft</getraenk>
</gast>
<gast>
<person>
<name>Zacharias Zottelig</name>
</person>
</gast>
</party>
Now i want a list of all names of the guests.
At the moment i' using jdom in the follow java-class:
listChildren(myfile.doc.getRootElement());
calls this function:
public static void listChildren(org.jdom.Element current) {
//Array
String laenderarray[] = new String[10];
int anzahl = 0;
System.out.println(current.getName());
java.util.List children = current.getChildren();
java.util.Iterator iterator = children.iterator();
while (iterator.hasNext()) {
org.jdom.Element child = (org.jdom.Element) iterator.next();
System.out.println(child);
String temp = child.getName();
System.out.println("Name: " + temp);
if(temp == "name") {
System.out.println("Name ist: " + child.getText());
laenderarray[anzahl] = child.getText();
anzahl++;
// here's the problem. I don't want to search the next children, but
// get the "following sibling"
// that gets me to the actual <guest>
//child = child.getParent().getParent();
// but how do i get to the next one ??
}
// go on
listChildren(child);
}
}
I haven't found any way to do this in jdom... Isn't there any ?
If i have to use jaxen and xpath (i don't hope so), how do i have to do this - i have absolutly no idea.
Thanx in advance for any response,
daniel
---------------------------------------
Visit me @:
short version: Is there a possibility using jdom to get the "following-sibling" of an element.
long version: Assume i've got the following xml file:
<party datum="31.12.01">
<gast>
<person>
<name>Albert Angsthase</name>
</person>
<getraenk>Wein</getraenk>
</gast>
<gast>
<person>
<name>Martina Mutig</name>
</person>
<getraenk>Apfelsaft</getraenk>
</gast>
<gast>
<person>
<name>Zacharias Zottelig</name>
</person>
</gast>
</party>
Now i want a list of all names of the guests.
At the moment i' using jdom in the follow java-class:
listChildren(myfile.doc.getRootElement());
calls this function:
public static void listChildren(org.jdom.Element current) {
//Array
String laenderarray[] = new String[10];
int anzahl = 0;
System.out.println(current.getName());
java.util.List children = current.getChildren();
java.util.Iterator iterator = children.iterator();
while (iterator.hasNext()) {
org.jdom.Element child = (org.jdom.Element) iterator.next();
System.out.println(child);
String temp = child.getName();
System.out.println("Name: " + temp);
if(temp == "name") {
System.out.println("Name ist: " + child.getText());
laenderarray[anzahl] = child.getText();
anzahl++;
// here's the problem. I don't want to search the next children, but
// get the "following sibling"
// that gets me to the actual <guest>
//child = child.getParent().getParent();
// but how do i get to the next one ??
}
// go on
listChildren(child);
}
}
I haven't found any way to do this in jdom... Isn't there any ?
If i have to use jaxen and xpath (i don't hope so), how do i have to do this - i have absolutly no idea.
Thanx in advance for any response,
daniel
---------------------------------------
Visit me @: