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
public static ArrayList<HashMap<String, String>> getWhoList(Node currentNode, String tagName) { String result = ""; ArrayList<HashMap<String, String>> whoArrayList = new ArrayList<HashMap<String, String>>(); NodeList childNodeList = currentNode.getChildNodes(); for (int i = 0; i < childNodeList.getLength(); i++) { Node childNode = childNodeList.item(i); if (childNode.getNodeName().equals(tagName)) { HashMap<String, String> whoMap = new HashMap<String, String>(); NamedNodeMap attrNodeMap = childNode.getAttributes(); Node activity = attrNodeMap.getNamedItem("activity"); Node email = attrNodeMap.getNamedItem("email"); Node name = attrNodeMap.getNamedItem("name"); if (activity != null) { whoMap.put("activity", activity.getNodeValue()); }//from w w w.j a va 2 s . co m if (email != null) { whoMap.put("email", email.getNodeValue()); } if (name != null) { whoMap.put("name", name.getNodeValue()); } whoArrayList.add(whoMap); } } return whoArrayList; }
From source file:Main.java
public static List<Node> getElementChilds(Node parentNode) { List<Node> listChild = new ArrayList<Node>(); if (!isElement(parentNode)) { return listChild; // return empty list } else {//from w w w.j av a2 s. c om NodeList childList = parentNode.getChildNodes(); for (int nodeId = 0; nodeId < childList.getLength(); nodeId++) { Node node = childList.item(nodeId); if (isElement(node)) { listChild.add(node); } } } return listChild; }
From source file:Main.java
/** * Scans a node and all of its children for nodes of a particular type. * * @param parent The parent node to search from. * @param recursiveSearch If the child nodes should be recursively searched. * @param nodeNames A single node name or list of node names to search for * @return a List of all the nodes found matching the nodeName under the parent */// ww w.j av a2 s . c o m protected static List<Node> getChildNodes(final Node parent, boolean recursiveSearch, final String... nodeNames) { final List<Node> nodes = new ArrayList<Node>(); final NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { final Node child = children.item(i); for (final String nodeName : nodeNames) { if (child.getNodeName().equals(nodeName)) { nodes.add(child); } if (recursiveSearch) { nodes.addAll(getChildNodes(child, true, nodeName)); } } } return nodes; }
From source file:Main.java
public static Node appendChildNodes(Node destNode, Node parentNode) { if (destNode != null && parentNode != null) { destNode.setTextContent(""); NodeList list = parentNode.getChildNodes(); if (list != null) { for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null) { copyInto(node, destNode); }/*ww w. j av a2 s . c o m*/ } } } return destNode; }
From source file:Main.java
/** * Method to get Values within AttributeValuePair as a java.util.Set *///from w w w . j ava2 s. c om public static Set getAttributeValuePair(Node node) { if (!node.getNodeName().equals(ATTR_VALUE_PAIR_NODE)) return (null); Set retVal = new HashSet(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); if (n.getNodeName().equalsIgnoreCase(VALUE_NODE)) { retVal.add(getValueOfValueNode(n)); } } return (retVal); }
From source file:org.owasp.benchmark.tools.BenchmarkCrawler.java
public static List<Node> getNamedChildren(String name, List<Node> list) { List<Node> results = new ArrayList<Node>(); for (Node n : list) { NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeName().equals(name)) { System.out.println("> " + child.getNodeName() + "::" + child.getNodeValue()); results.add(child);//w w w. j a v a2 s.co m } } } return results; }
From source file:Main.java
public static void setNodeValue(Node node, String name, String value) { String s = node.getNodeValue(); if (s != null) { node.setNodeValue(value);//from ww w .j a va 2s. c o m return; } NodeList nodelist = node.getChildNodes(); for (int i = 0; i < nodelist.getLength(); i++) { if (nodelist.item(i) instanceof Text) { Text text = (Text) nodelist.item(i); text.setData(value); return; } } return; }
From source file:Main.java
/** * Find all of the descendant elements of the given parent Node * whose tag name equals the given tag. * * @param parent The root of the xml dom tree to search. * @param tag The tag name to match./*from w w w. j ava2 s . com*/ * @param found The list of descendants that match the given tag. */ private static void findDescendants(Node parent, String tag, List found) { if (getNodeName(parent).equals(tag)) { found.add(parent); } NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); findDescendants(child, tag, found); } }
From source file:Main.java
public static String getText(Node node) { StringBuffer result = new StringBuffer(); if (!node.hasChildNodes()) return ""; NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) {/*from ww w. j a va2 s. c o m*/ Node subnode = list.item(i); if (subnode.getNodeType() == Node.TEXT_NODE) { result.append(subnode.getNodeValue()); } else if (subnode.getNodeType() == Node.CDATA_SECTION_NODE) { result.append(subnode.getNodeValue()); } else if (subnode.getNodeType() == Node.ENTITY_REFERENCE_NODE) { // Recurse into the subtree for text // (and ignore comments) result.append(getText(subnode)); } } return result.toString(); }
From source file:Main.java
/** * Find a Node with a given QName//from w ww.j a va2 s. c o m * * @param node parent node * @param name QName of the child we need to find * @return child node */ public static Node findNode(Node node, QName name) { if (name.getNamespaceURI().equals(node.getNamespaceURI()) && name.getLocalPart().equals(node.getLocalName())) return node; NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node ret = findNode(children.item(i), name); if (ret != null) return ret; } return null; }