Q:

how to get all roots of a child in xml using java

i have a xml file like below. 
<root>
 <subchildA>
    <childA>
         <dataA>data</dataA>
         <dataB>data</dataB>
    </childA>
 </subchildA>
 <subchildB>
    <childB>
         <dataA>data</dataA>
         <dataB>data</dataB>
    </childB>
 </subchildB>
</root>

i can get the node values eg(dataA or dataB 's value).  But i need to get all the roots of data nodes. 
eg dataA is in childA->subchildA->root.  i am using java DocumentBuilder for  reading.  
EDIT
using the below code i can recursively read nth child but i cant get all roots. 
public static void readNode( Node node) {
        String id;
        NodeList subList = node.getChildNodes();
        for (int j = 0; null ! = subList && j < subList.getLength(); j++) {
            Node tmpNode = subList.item(j);
            if (tmpNode.hasChildNodes()) {
                Element element = (Element) tmpNode;
                id = element.getAttribute("id");

                    System.out.println( id + ":"
                            + tmpNode.getTextContent());

                readNode( tmpNode);
            }
        }
    }

A:

You have to traverse xml backwards to reach root node. 
Using Node Node.getParentNode() method you can get parent node of the current node and apply same on parent node until you reach required node(Parent).