List of usage examples for org.w3c.dom Element getFirstChild
public Node getFirstChild();
From source file:Utils.java
public static Element getFirstChild(Element e, String local) { for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element c = (Element) n; if (c.getLocalName().equals(local)) return c; }// w w w .j a v a2 s . c o m } return null; }
From source file:Main.java
/** * Determine whether an element has any child elements. * @param element the element to check.// ww w. j a v a 2 s . c o m * @return true if the element has child elements; false otherwise. */ public static boolean hasChildElements(Element element) { Node child = element.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) return true; child = child.getNextSibling(); } return false; }
From source file:Main.java
License:asdf
public static void deleteFirstElement(Document doc) { Element root = doc.getDocumentElement(); Element child = (Element) root.getFirstChild(); root.removeChild(child);/*from w w w . j ava 2 s. c o m*/ }
From source file:Main.java
public static Node getTextChild(Element aNode) { for (Node i = aNode.getFirstChild(); i != null; i = i.getNextSibling()) if (i.getNodeType() == Node.TEXT_NODE) return i; return null;/*from w w w. j av a 2s . c o m*/ }
From source file:Main.java
/** * Get the indexed Element.//from w ww.j ava 2s . c o m * <p> * Similar to <code>Element.getChildNodes.item</code>, but ignores any Nodes (such as * indentation TextNodes). */ public static Element getFirstChildElement(Element parent) { Node node = parent.getFirstChild(); while (node != null && !(node instanceof Element)) { node = node.getNextSibling(); } return (Element) node; }
From source file:Main.java
public static void addAttribute(Document doc) { Element root = doc.getDocumentElement(); Element person = (Element) root.getFirstChild(); person.setAttribute("company", "yourCom"); }
From source file:Main.java
public static String getTextNode(Element aNode) { for (Node i = aNode.getFirstChild(); i != null; i = i.getNextSibling()) if (i.getNodeType() == Node.TEXT_NODE) return i.getNodeValue(); return null;//from w w w . jav a 2 s.c om }
From source file:Main.java
public static String getText(Element element) { try {//from w w w . ja v a 2 s . co m String text = element.getFirstChild().getNodeValue(); return null == text ? "" : text; } catch (Exception e) { return ""; } }
From source file:Main.java
public static String getTextValue(Element ele, String tagName) { String textVal = null;//w w w . j a v a2 s. com NodeList nl = ele.getElementsByTagName(tagName); if (nl != null && nl.getLength() > 0) { Element el = (Element) nl.item(0); textVal = el.getFirstChild().getNodeValue(); } return textVal; }
From source file:Main.java
public static String getElementBody(Element element) { org.w3c.dom.Node valueNode = element.getFirstChild(); if (valueNode == null) { return null; }//ww w. j av a 2 s . c om if (valueNode.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { return valueNode.getNodeValue(); } else { return null; } }