// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XmlParse {
    public static void main(String[] args) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = factory.newDocumentBuilder();
        Document doc=docBuilder.parse("C:\\ns.xml");
        Node root = doc.getDocumentElement();
        System.out.println(root);
        NodeList childs = root.getChildNodes();
        for(int i = 0; i < childs.getLength(); i++) {
            if(childs.item(i).getNodeType() == Node.ELEMENT_NODE) {
                Element elm = (Element)childs.item(i);
                System.out.println(elm);
                NodeList childs2 = elm.getChildNodes();
                for(int j = 0; j < childs2.getLength(); j++) {
                    if(childs2.item(j).getNodeType() == Node.ELEMENT_NODE) {
                        Element elm2 = (Element)childs2.item(j);
                        System.out.println(elm2);
                        NodeList childs3 = elm2.getChildNodes();
                        for(int k = 0; k < childs3.getLength(); k++) {
                            if(childs3.item(k).getNodeType() == Node.TEXT_NODE) {
                                Node n = childs3.item(k);
                                System.out.println(n);
                            }
                        }
                    }
                }
            }
        }
    }
}
