Java examples for XML:XML Element Child
get XML Child Element As Integer
//package com.java2s; import org.w3c.dom.Element; public class Main { public static int getChildAsInteger(Element parent, String childName) { if (doesElementContainChildren(parent, childName)) { return Integer.parseInt(getFirstChildElement(parent, childName) .getTextContent());/*from w w w. j a va2s.c o m*/ } return -1; } public static boolean doesElementContainChildren(Element parent, String... childNames) { boolean missingChild = false; for (String childName : childNames) { if (parent.getElementsByTagName(childName).getLength() == 0) { missingChild = true; } } if (missingChild) return false; else return true; } public static Element getFirstChildElement(Element parent, String childName) { if (parent.getElementsByTagName(childName).getLength() > 0) { return (Element) parent.getElementsByTagName(childName).item(0); } return null; } }