Recursive method doesn't work - ArrayList<String>

charlowit

New Member
I have a problem with a recursive method , that put all element of an XML File in an ArrayList\[code\]<?xml version="1.0" encoding="iso-8859-1"?><country> <name> France </name> <city> Paris </city> <region> <name> Nord-Pas De Calais </name> <population> 3996 </population> <city> Lille </city> </region> <region> <name> Valle du Rhone </name> <city> Lyon </city> <city> Valence </city> </region> </country>\[/code\]But my function does'nt complete all round (Get all element) : the result is [country, name, city, region, region] but i want to get all element [country, name, city, region,name,population,region,name,city,city], i think that the recursively call is not in the right place, this is my code\[code\]public static ArrayList<String> TreeToArray (Node node){ ArrayList<String> ArrayNoeud = new ArrayList<String> (); ArrayNoeud.add(node.getNodeName()); NodeList nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n instanceof Element) { ArrayNoeud.add(n.getNodeName()); } TreeToArray(n); } return ArrayNoeud; }\[/code\]
 
Back
Top