parse into array using JDOM! please help
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