I have a XML org.w3c.dom.Document object.
It looks sorta like this:
<A>
<B>
<C/>
<D/>
<E/>
<F/>
</B>
<G>
<H/>
<H/>
<J/>
</G>
</A>
How can I convert the Document object so that it strips off the root node and returns another Document object subset (selected by name) that looks like this:
<G>
<H/>
<H/>
<J/>
</G>
I am hoping for something like this:
...
Document doc = db.parse(file);
Document subdoc = doc.getDocumentSubsetByName("G"); //imaginary method name
NodeList nodeList = subdoc.getElementsByTagName("H");
But I am having trouble finding such a thing.
The answer turns out to be something like this:
...
Document doc = db.parse();
doc.getDocumentElement.normalize();
NodeList a = doc.getElementsByTagName("A");
Element AsubNode = null;
if (a.item(0) != null) {
AsubNode = (Element) a.item(0);
nodeList = AsubNode.getElementsByTagName("G");
...