How to get childnodes using DOM in Java

GowLorWearo

New Member
I have this XML.\[code\] <employees> <employee tag="FT" name="a"> <password tag="1"/> <password tag="2"/></employee><employee tag="PT" name="b"> <password tag="3"/> <password tag="4"/></employee></employees>\[/code\]I am trying to get the child nodes of each employee and put the tag value of child nodes i.e. password's tag value in a list.\[code\]nl = doc.getElementsByTagName("employee");for(int i=0;i<nl.getLength();i++){ NamedNodeMap nnm = nl.item(i).getAttributes(); NodeList children = nl.item(i).getChildNodes(); passwordList = new ArrayList<String>(); for(int j=0; j<children.getLength();j++){ NamedNodeMap n = children.item(j).getAttributes(); passwordTagAttr=(Attr) n.getNamedItem("tag"); passwordTag=stopTagAttr.getValue(); passwordList.add(passwordTag); }}\[/code\]I am getting value of children =4 when I debug. But I should be getting it 2 for each loop Please help.
 
Back
Top