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
private static String getDate(Node node) { String date = ""; NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node curNode = nodeList.item(i); if ("date".equalsIgnoreCase(curNode.getNodeName())) { date = curNode.getTextContent().replace("\"", ""); break; }/* www. ja v a2s . c o m*/ } return date; }
From source file:Main.java
public static Node getDescendent(Node node, String nodeName) throws IOException { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeName().equals(nodeName)) { return child; }/*from w w w . j a v a 2 s . c om*/ } return null; }
From source file:Main.java
public static Vector getChildrenElementsByTag(Node node, String name) { Vector result = new Vector(); NodeList nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) if (nl.item(i) instanceof Element && (((Element) nl.item(i)).getTagName().equals(name) || name == null)) { result.add(nl.item(i));/* w w w .j a v a 2s. c o m*/ //System.out.println(nl.item(i).toString()); //System.out.println(((Element)nl.item(i)).getAttribute("className")); //System.out.println(((Element)nl.item(i)).getTagName()); } return result; }
From source file:Main.java
public static List<Node> getNodeListByName(Node node, String name, List<Node> finalNodeList) { NodeList nodeList = node.getChildNodes(); //System.out.println("child node name: "+node.getNodeName()); if (nodeList == null) return null; for (int i = 0; i < nodeList.getLength(); i++) { Node candNode = nodeList.item(i); if (candNode.getNodeName().equals(name)) { finalNodeList.add(candNode); }/*from w w w.jav a 2 s . co m*/ getNodeListByName(nodeList.item(i), name, finalNodeList); } return finalNodeList; }
From source file:Main.java
/** Returns all child <code>Node</code>s with the given name stored in a * <code>Vector</code>.// ww w . j a v a 2 s . c om * * @param node The parent node to be searched for * @param name The element name to search for * @return <code>Vector</code> of found </code>Node</code>s */ public static Vector getSubnodesByName(Node node, String name) { Vector retVal = null; NodeList nl = node.getChildNodes(); if (nl != null && nl.getLength() != 0) { for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getNodeName().equals(name)) { if (retVal == null) retVal = new Vector(); retVal.addElement(nl.item(i)); } } } return retVal; }
From source file:Main.java
public static List<Node> getNodeListByName(Node node, String name, List<Node> finalNodeList) { NodeList nodeList = node.getChildNodes(); System.out.println("child node name: " + node.getNodeName()); if (nodeList == null) return null; for (int i = 0; i < nodeList.getLength(); i++) { Node candNode = nodeList.item(i); if (candNode.getNodeName().equals(name)) { finalNodeList.add(candNode); }/* w ww.ja v a2 s. co m*/ getNodeListByName(nodeList.item(i), name, finalNodeList); } return finalNodeList; }
From source file:Main.java
/** * returns list of child Element Nodes for a given, parsed XML node * /*from w w w . j ava 2s .c o m*/ * @param xmlNode parsed XML Node for which child Nodes are to be returned * @return List of child Element Nodes of xmlNode **/ public static final List<Element> getChildElementNodes(final Node xmlNode) { final NodeList children = xmlNode.getChildNodes(); if (children == null) { return null; } final int childrenCnt = children.getLength(); final List<Element> list = new ArrayList<Element>(childrenCnt); for (int i = 0; i < childrenCnt; i++) { // Then loop through them looking for search criteria node final Node childNode = children.item(i); if (childNode.getNodeType() == Node.ELEMENT_NODE) { list.add((Element) childNode); } } return list; }
From source file:Main.java
private static void getChildrenByName(Node node, String name, Collection<Node> nodes) { NodeList list = node.getChildNodes(); for (int i = 0, len = list.getLength(); i < len; i++) { Node child = list.item(i); if (child.getNodeName().equalsIgnoreCase(name)) { nodes.add(child);//from ww w . j a v a2s . c o m } } }
From source file:Main.java
public static String getTextContent(Node e) { StringBuilder sb = new StringBuilder(); NodeList children = e.getChildNodes(); if (children != null) { for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); if (n.getNodeType() == Node.TEXT_NODE) { sb.append(n.getNodeValue()); }/*www .j a va 2 s. co m*/ } } return sb.toString(); }
From source file:Main.java
public static Node getChildNode(Node parentNode, String nodeName) { Node node = null;//from w ww . j a va 2s.com NodeList nodeList = parentNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node childNode = nodeList.item(i); if (childNode.getNodeType() == Node.ELEMENT_NODE) { if (((Element) childNode).getNodeName().equals(nodeName)) { node = childNode; break; } } } return node; }