java code to get all leaf nodes of a xml
try {
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("input.xml");
final XPathExpression xpath = XPathFactory.newInstance().newXPath().compile("//*[count(./*) = 0]");
final NodeList nodeList = (NodeList) xpath.evaluate(doc, XPathConstants.NODESET);
for(int i = 0; i < nodeList.getLength(); i++) {
final Element el = (Element) nodeList.item(i);
System.out.println(el.getNodeName());
}
} catch (Exception e) {
e.printStackTrace();
}
Also in Java:
- declare hashmap java
- indexof java
- Compare integers java sort
- java djikstra's algorithm
- padding a string with 0 in java
- Filebody in java
- place.getlatlng() returning null
- java singleton implementation
- ternary operator java
- java observable
- java read each lines in file
- get tfidf score for a sentence
- convert int to string java
- JSONObject java
- java 8 stream group by example
- java thread
- java mysql springboot jpa stackoverflow
- java import
- java insert array
- java create circle
- java file exists
- code to include layout from java in android
- java merge sort
- how to print in java