Java examples for XML:XML Element Child
get XML Child Element As Float
//package com.java2s; import org.w3c.dom.Element; public class Main { public static float getChildAsFloat(Element parent, String childName) { if (doesElementContainChildren(parent, childName)) { return Float.parseFloat(getFirstChildElement(parent, childName) .getTextContent());// www .j a va 2 s.com } return -1f; } 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; } }