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 How to use NavigableMap? 
Java :: labeled statement in java ex 
Java :: How to send saved CSV file via email 
Java :: java loop find index 
Java :: convert code from kotlin to java 
Java :: java stream dristinct 
Java :: random class in java 
Java :: getsmallestnumber 
Java :: java disable stack trace 
Java :: from which android version onwards cardelevation supports? 
Java :: condensed for loop java 
Java :: exponet 
Java :: add image in loggin view spring boot security 
Java :: one space diagonally in java 
Java :: expression régulière seulement un espace java 
Java :: Java Default Access Modifier package one 
Java :: for loop optimized java 
Java :: Get directory in android java 
Java :: Iterating The Queue Elements 
Java :: difference between final and constant in java 
Java :: implement elasticsearch filter in java 
Java :: Java Standard Library Method 
Java :: cellrangeaddress in set border example in java 
Java :: DMC5 performace mod 
Java :: public static void main(String args[]) { level input=new level(System.in); FirstPractice obj1=new FirstPractice(); obj1.loosing(1000); } 
Java :: android studio epoch to localdatetime 
Java :: split() String android 
Java :: UIManager.setLookAndFeel Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke because "style" is null 
Java :: import java.util.* 
Java :: licenceurl 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =