List of usage examples for org.w3c.dom Element getChildNodes
public NodeList getChildNodes();
NodeList
that contains all children of this node. From source file:Main.java
/** * An iterable for all the Element childs of a node * //from w ww.ja v a 2 s .c o m * @param n * the node get the children from * @return An iterable for all the Element childs of a node */ public static Iterable<Element> elements(Element n) { int sz = n.getChildNodes().getLength(); ArrayList<Element> elements = new ArrayList<Element>(sz); for (int idx = 0; idx < sz; idx++) { Node node = n.getChildNodes().item(idx); if (node instanceof Element) elements.add((Element) node); } return elements; }
From source file:Main.java
public static Element getChildByName(Element parent, String nodeName) { NodeList nodes = parent.getChildNodes(); int len = nodes.getLength(); if (nodes != null && len > 0) { for (int i = 0; i < len; i++) { if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE && nodes.item(i).getNodeName().equals(nodeName)) { return (Element) nodes.item(i); }// w w w . j ava2s . c om } } return null; }
From source file:Main.java
public static List getChildElementByTagName(Element parentElement, String tagName) { NodeList list = parentElement.getChildNodes(); ArrayList l = new ArrayList(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i);/*from ww w . ja v a2 s . com*/ if ((n instanceof Element) && n.getNodeName().equals(tagName)) l.add(n); } return l; }
From source file:Main.java
public static List<Element> getChildElements(Element parent) { NodeList nodes = parent.getChildNodes(); ArrayList elements = new ArrayList(); for (int i = 0; i < nodes.getLength(); ++i) { Node node = nodes.item(i); if (node instanceof Element && node.getParentNode() == parent) { elements.add((Element) node); }/*from ww w .j av a 2 s.c om*/ } return elements; }
From source file:Main.java
public static Element getChildElementByTagName(Element ele, String childEleName) { NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i);/*from w w w.j a va 2 s. com*/ if (node instanceof Element && nodeNameMatch(node, childEleName)) { return (Element) node; } } return null; }
From source file:Main.java
/** * Remove all child nodes of the given node. * * @param aElement/* w w w . j a v a 2s. c o m*/ * The element whose children are to be removed. */ public static void removeAllChildElements(@Nonnull final Element aElement) { while (aElement.getChildNodes().getLength() > 0) aElement.removeChild(aElement.getChildNodes().item(0)); }
From source file:Main.java
public static ArrayList<Element> getChildrenByTagName(Element node, String tagname) { NodeList childrenNode = node.getChildNodes(); ArrayList<Element> matches = new ArrayList<Element>(); for (int i = 0; i < childrenNode.getLength(); i++) { if (childrenNode.item(i) instanceof Element) { Element child = (Element) childrenNode.item(i); if (child.getTagName().equals(tagname)) { matches.add(child);/*from w ww .jav a2s . com*/ } } } return matches; }
From source file:Main.java
/** * Get the text for an element, which is considered the first Text child element. * @param element/* www . j a va 2 s. com*/ * @returns the text or <code>null</code> */ public static String getText(Element element) { NodeList nodeList = element.getChildNodes(); if (nodeList.item(0) instanceof Text) { return nodeList.item(0).getTextContent(); } return null; }
From source file:Main.java
public static Element find(Element element, String name) { NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if ((child instanceof Element) && child.getNodeName().equals(name)) { return (Element) child; }//from w w w. j a v a 2 s .c o m } return null; }
From source file:Main.java
public static List<Node> getChildElementsByTagName(Element ele, String childEleName) { NodeList nl = ele.getChildNodes(); List<Node> childEles = new ArrayList<Node>(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i);// w w w . j a v a2 s . c o m if (node instanceof Element && childEleName.equals(node.getNodeName()) || childEleName.equals(node.getLocalName())) { childEles.add(node); } } return childEles; }