Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

parse into array using JDOM! please help

843834Aug 26 2007
hey,
i've managed to parse an xml document using JDOM
i[b] need to be able to parse it and store the text (the value of each node) into an array, and then insert into db etc.

the problem is with the recursive function listChildren which calls itself... can someone tell me where do i insert the block of code such that i can store it into an array of string.

here's the code:
public static void parse(String stock) throws SQLException
{
SAXBuilder builder = new SAXBuilder();
Reader r = new StringReader(stock);
Document doc = builder.build(r);
Element root = doc.getRootElement();
listChildren(root, 0);
}

public static void listChildren(Element current, int depth) throws Exception
{
String nodes = current.getName();
System.out.println(nodes + " : " + current.getText());

List children = current.getChildren();
Iterator iterator = children.iterator();
while(iterator.hasNext())
{
Element child = (Element) iterator.next();
listChildren(child, depth+1);
}
}


i'm looking for something like:

a=current.getText();
but i donno where to include this line of code, please help

cheers,
Shivek Sachdev
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 23 2007
Added on Aug 26 2007
0 comments
201 views