Iterate over DOM Nodelist

I have an XML in the form of
I want to iterate over all the elements inside fb_responses, so that whenever a tag is encountered like fb_input_approve or fb_response, I can do some action.
This is what I am doing (attached code snippet)
But in the nodelist, I am getting only one element.

Can someone please let me know how to achieve this using DOM

NodeList responsesNodeList = document.getElementsByTagName("fb_responses");
       System.out.println("resposne node list lenght :  "+responsesNodeList.getLength());
       for(int i=0; i<responsesNodeList.getLength(); i++) {
           Node childOfResponses = responsesNodeList.item(i);
           if (childOfResponses.getNodeType() == childOfResponses.ELEMENT_NODE) {
                   String strChildOfResponses = childOfResponses.getNodeName();
                   System.out.println(childOfResponses.getNodeName()+"  :  "+childOfResponses.getNodeValue());
                   if(strChildOfResponses.equalsIgnoreCase("fb_input_approve")) {
           IXMLCreator cfxml = new CreateApproverXML();
           StringBuffer xmlChunck = cfxml.getXMLChunck(response_id, session);

Open in new window

Who is Participating?
In the XML you only have one <fb_responses> so thats why you only get one element. :)
Which XMLReader are you using by the way?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.