I want to check if an XML document contains a human element anywhere. I can check all the elements of the first generation very simply:
NodeList nodeList = root.getChildNodes(); for(int i=0; i<nodeList.getLength(); i++){ Node childNode = nodeList.item(i); if (childNode.getNodeName() == "person") {
And I can add more loops to go into sub-elements, but I would need to know how many nested loops I need to insert in order to determine how far to drill in the document. I could have nested 10 cycles, and as a result, the human element nested 12 elements in depth in this document. I need to remove the element, no matter how deep it is nested.
Is there a way to assemble elements from a whole document? How to return text values of all tags as an array or iterate over it?
Something similar to the python elementtree 'findall' method is possible:
for person in tree.findall('//person'): personlist.append(person)
java dom xml
directedition
source share