Actually I have an XML document. I would like to print the children of the root element of the document using a utility in org.w3c.Dom without printing the document headers.
So I need a utility in org.w3c.Dom to print a Node only. any help please ?
Actually I have an XML document. I would like to print the children of the root element of the document using a utility in org.w3c.Dom without printing the document headers.
So I need a utility in org.w3c.Dom to print a Node only. any help please ?
Printing isn't the job of the Java DOM API. There are no printing APIs in it at all.
You can certainly visit the children of the root element, look at the type of each Node, and print what you want to print.
Assuming you have an org.w3c.dom.Document
you can print the names of the child nodes of the root element with something like:
// assuming: Document doc = ...;
NodeList childNodes = doc.getDocumentElement().getChildNodes();
for(int i = 0; i < childNodes.getLength(); i++){
System.out.println(childNodes.item(i).getNodeName());
}
Realistically, if you want to navigate the DOM using the org.w3c.dom
utilities you'll need to figure out which API calls are most relevant for you.
An excellent starting point is the API documentation (that I referred to to answer your question). Here's the relevant pages for this particular answer: