List of usage examples for org.w3c.dom Node getChildNodes
public NodeList getChildNodes();
NodeList
that contains all children of this node. From source file:Main.java
/** * Extracts the text from the given element. * Element.getTextContet() is java5 specific, so we need to use this until we drop 1.4 support. */// w w w . j a v a 2 s. c om public static String getTextContent(Node element) { StringBuffer text = new StringBuffer(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child instanceof Text) { text.append(child.getNodeValue()); } } return text.toString(); }
From source file:Main.java
/** * Get the first direct child element of the passed element. * * @param aStartNode/*from w w w. ja va 2 s .c o m*/ * The element to start searching. * @return <code>null</code> if the passed element does not have any direct * child element. */ @Nullable public static Element getFirstChildElement(@Nonnull final Node aStartNode) { final NodeList aNodeList = aStartNode.getChildNodes(); final int nLen = aNodeList.getLength(); for (int i = 0; i < nLen; ++i) { final Node aNode = aNodeList.item(i); if (aNode.getNodeType() == Node.ELEMENT_NODE) return (Element) aNode; } return null; }
From source file:Main.java
public static Element readFirstChild(Node parentNode, String nodeName) { if (parentNode != null) { NodeList children = parentNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeName().equals(nodeName)) return (Element) children.item(i); }/*from www. jav a 2s . com*/ } return null; }
From source file:Main.java
public static Element getElementNode(Node root, String nodeString) { NodeList nlist = root.getChildNodes(); for (int i = 0; i < nlist.getLength(); i++) { if (nlist.item(i) instanceof Element) { if (nlist.item(i).getNodeName().equalsIgnoreCase(nodeString)) { return (Element) nlist.item(i); }// w ww . j a v a 2 s . com if (nlist.item(i).hasChildNodes()) { Element retNode = getElementNode(nlist.item(i), nodeString); if (retNode != null) { return retNode; } } } } return null; }
From source file:Main.java
public static Node getChildNode(String name, Node node) { if (node == null) { return null; }/*ww w . java 2 s . co m*/ NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node no = list.item(i); if (no.getNodeName().equalsIgnoreCase(name)) { return no; } } return null; }
From source file:Main.java
public static Node[] getChildrenNamed(Node node, String name) { ArrayList v = new ArrayList(); NodeList nList = node.getChildNodes(); for (int i = 0; i < nList.getLength(); i++) { Node n = nList.item(i);/* ww w . jav a 2 s. c o m*/ if (n.getNodeName().equalsIgnoreCase(name)) { v.add(n); } } Node[] nodeArray = new Node[v.size()]; nodeArray = (Node[]) v.toArray(nodeArray); return nodeArray; }
From source file:Main.java
public static List getChildrenElement(Node n, String childTagName) { List lst = new ArrayList(); NodeList nl = n.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node cn = nl.item(i);// w w w . j a va2 s .c o m if ((cn.getNodeType() == Node.ELEMENT_NODE) && (cn.getNodeName().equals(childTagName))) { lst.add(cn); } } return lst; }
From source file:Main.java
public static Node findChildNode(Node parentNode, int type) { Node foundNode = null;//from w w w . j a v a 2 s .c o m NodeList nl = parentNode.getChildNodes(); int len_nl = nl.getLength(); for (int j = 0; j < len_nl; j++) { foundNode = nl.item(j); if (foundNode.getNodeType() == type) return foundNode; } return null; }
From source file:Main.java
/** * Determines the first child node of the parent with the specified tag * name./*w ww .j a v a 2s . c om*/ * * @param parent The parent node of the child node to be determined. * @param nodeName The name of the child node to be determined. * * @return The determined child node with the given name. */ public static Node getChildWithName(Node parent, String nodeName) { if (parent != null) { NodeList childs = parent.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { Node child = childs.item(i); if ((child.getLocalName() != null) && child.getLocalName().equals(nodeName)) { return childs.item(i); } } } return null; }
From source file:Main.java
public static List<Node> getChildNodes(Node dataNode) { List<Node> returnList = new ArrayList<Node>(); NodeList list = dataNode.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node.getNodeType() != Node.TEXT_NODE) { returnList.add(node);//from w w w .j a va 2s.c om } } return returnList; }