Java tutorial
//package com.java2s; // publish, distribute, sublicense, and/or sell copies of the Software, import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { /** * Returns the main node of the XML document * * @param doc the XML document * @return the main node */ public static Node getMainNode(Document doc) { for (int i = 0; i < doc.getChildNodes().getLength(); i++) { Node node = doc.getChildNodes().item(i); if (!node.getNodeName().equals("#text") && !node.getNodeName().equals("#comment")) { return node; } } throw new RuntimeException("main node in XML file could not be retrieved"); } }