recursive method max depth- static variable

pmnonline

New Member
i want to get the maximum depth of an XML file using a recursive method firstly i have declared the variable\[code\] public static int maxdepth=0; private static void GetDepth(NodeList nl, int level,int maxdepth) { level++; if (maxdepth<level) { maxdepth= level; } if(nl != null && nl.getLength() > 0){ for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n instanceof Element) { GetDepth(n.getChildNodes(), level, maxdepth); } } }} public static void main(String[] args) { NodeList nl = root.getChildNodes(); GetDepth(nl,level,maxdepth); System.out.println(maxdepth); }\[/code\]and when i would display the value of variable maxdepth, I receive the value 0, as the declaration
 
Back
Top