List of usage examples for org.w3c.dom NodeList getLength
public int getLength();
From source file:Main.java
public static Node getChildNode(Node node, String childName) { NodeList nodes = node.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node curNode = nodes.item(i); if (curNode.getLocalName() != null && curNode.getLocalName().equals(childName)) { return curNode; }/* w ww .ja v a 2 s .com*/ } return null; }
From source file:Main.java
public static String parseString(Element xmlElement, String tagName) { NodeList items = xmlElement.getElementsByTagName(tagName); if (items.getLength() == 0) return null; else//from w ww . j av a2 s . c o m return items.item(0).getTextContent(); }
From source file:Main.java
public static Element FindElement(Element parent_element, String element_name, String child_element_name) { NodeList match = parent_element.getElementsByTagName(element_name); if (match.getLength() == 0) return null; Element m = (Element) match.item(0); if (child_element_name != null) m = FindElement(m, child_element_name, null); return m;// w w w . j av a 2 s. c om }
From source file:Main.java
public static final List<Element> getChildElements(Element element) { List<Element> childElements = new ArrayList<Element>(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); if (item.getNodeType() == Node.ELEMENT_NODE) { childElements.add((Element) item); }//from www . j a v a2 s .c o m } return childElements; }
From source file:Main.java
public static String getValue(Element e, String tagName) { try {//from w ww . j a v a 2 s .c om // get node lists of a tag name from a Element NodeList elements = e.getElementsByTagName(tagName); if (elements.getLength() == 0) { return null; } Node node = elements.item(0); return node.getTextContent(); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:Main.java
public static Node getChildNode(Node node, String nodeName) { if (node.getNodeType() == Node.ELEMENT_NODE) { NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node n = nodeList.item(i); if (n.getNodeName().equals(nodeName)) { return n; }//from w ww . ja va 2s . c o m } } return null; }
From source file:Main.java
/** * Gets the first child element.//ww w. j a va 2 s . c o m * * @param e the element. * @return the first child element. */ public static Element getFirstChildElement(Element e) { if (e != null) { NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { return (Element) node; } } } return null; }
From source file:Main.java
/** * Utility method that returns the first child element * identified by its getName.//from w w w. j a v a 2 s . c o m * @param ele the DOM element to analyze * @param childName the child element getName to look for * @return the <code>org.w3c.dom.Element</code> creating, * or <code>null</code> if none found */ public static Element getChildElement(Element ele, String childName) { NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameEquals(node, childName)) return (Element) node; } return null; }
From source file:Main.java
/** * Returns the child of the given node which has the specified name * If no such node exists, returns null// ww w. ja va 2s . c om */ public static Node findChild(Node parent, String name) { // Iterate through the collection of children NodeList nodes = parent.getChildNodes(); for (int a = 0; a != nodes.getLength(); ++a) { Node node = nodes.item(a); if (node.getNodeName().equals(name)) { // This is the one return node; } } // No such node return null; }
From source file:Main.java
/** * Returns the first child element found with the specified tag name * @param node The node to search//from w w w .j av a 2 s . com * @param element The element tag name to search for * @return The matching element Node */ public synchronized static Node getFirstElementIgnoreCase(Node node, String element) { if (node != null && element != null) { NodeList nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase(element)) { return n; } } } return null; }