Answers for "how to print leaf nodes of a binary tree"

0

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();
}
Posted by: Guest on April-29-2020

Code answers related to "how to print leaf nodes of a binary tree"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language