Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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();
}
Comment

PREVIOUS NEXT
Code Example
Java :: java file and stream 
Java :: BasicAWSCredentials 
Java :: x squared unicode java code 
Java :: enum to get status name from list using status id 
Java :: convert text type to int java 
Java :: with uses in python 
Java :: exception in thread "main" java.lang.arrayindexoutofboundsexception: 10 
Java :: nbubble sort java 
Java :: javafx how to put multiple handlers in the same line 
Java :: tipe data c++ 
Java :: pojo api testing 
Java :: java overloading 
Java :: setUndecorated java 
Java :: android how to change focus on confirm button on keyboard 
Java :: download a website as string kotlin 
Java :: Check if service running in the background 
Java :: how to get the length of a jagged array java 
Java :: a java program must have at least one of these: 
Java :: convert from java to kotlin online 
Java :: java was started but returned exit code=13 
Java :: how to return custom value in api spring boot 
Java :: similar thing as pair in c++ in java 
Java :: efficient generic duplicate finding class java 
Java :: Java Classs Decomiler free 
Java :: java replace nans with 0 csv line 
Java :: speak function in java 
Java :: use scanner class in global scope java 
Java :: java new.JFrame(); 
Java :: ava program to add two numbers taking input from user 
Java :: open youtube in landscape mode on button click in android progmatically 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =