List of usage examples for org.w3c.dom Node getNodeName
public String getNodeName();
From source file:Main.java
/** * Finds the first child of a node with the given name * @param parent the parent node/*from w ww . ja v a 2s. c o m*/ * @param name the name * @return the child node */ public static Node findFirstChild(Node parent, String name) { NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node node = children.item(i); if (name.equals(node.getNodeName())) { return node; } } return null; }
From source file:Main.java
public static void setAllIdentityAttribute(Document document, String attributeValue) { NodeList propertyList = document.getElementsByTagName("Property"); for (int i = 0; i < propertyList.getLength(); i++) { Node node = propertyList.item(i); for (int j = 0; j < node.getAttributes().getLength(); j++) { Node attribute = node.getAttributes().item(j); if (attribute.getNodeName().equals("name") && attribute.getNodeValue().equals(attributeValue)) { Element element = (Element) node; element.setAttribute("isIdentity", "true"); }//from ww w . j av a 2 s .c o m } } }
From source file:Main.java
private static Map<String, Object> getAttributes(Node node) { NamedNodeMap attribs = node.getAttributes(); int attribCount = attribs.getLength(); Map<String, Object> map = new LinkedHashMap<>(attribCount); for (int j = 0; j < attribCount; j++) { Node attrib = attribs.item(j); map.put(attrib.getNodeName(), attrib.getNodeValue()); }/* www. j a v a2 s . c om*/ return map; }
From source file:Main.java
public static Element getSingleElementByName(Node node, String name) { NodeList nodeList = node.getChildNodes(); int count = nodeList.getLength(); for (int i = 0; i < count; i++) { Node child = nodeList.item(i); if (child instanceof Element && child.getNodeName().equals(name)) { return (Element) child; }/*w ww . j av a 2s . c o m*/ } return null; }
From source file:Utils.java
/** * Search for a named child of a given node * @param currentNode Starting point for our search * @param tagName Node name to look up//from w w w . j a v a 2s. co m * @return matching Node (null if none) */ public static Node getChildSiblingByName(Node currentNode, String tagName) { Node node = currentNode.getFirstChild(); while ((node != null) && (!node.getNodeName().equals(tagName))) { node = node.getNextSibling(); } return node; }
From source file:Main.java
public static void printNodeList(ArrayList<Node> nodeList) { StringBuffer buffer = new StringBuffer(); for (Node node : nodeList) { buffer.append(node.getNodeName() + " = " + node.getNodeValue() + " Attributes: " + attributesStr(node) + "\n"); }/* w w w .j a va2 s .c om*/ logger.info(buffer); }
From source file:Main.java
public static String getChildNodeValueOf(Node node, String tagName) { if (tagName.equals(node.getNodeName())) { return getValueOf(node); }/*from w w w . j a v a 2 s . c om*/ for (Node temp = node.getFirstChild(); temp != null; temp = temp.getNextSibling()) { if (temp.getNodeType() == Node.ELEMENT_NODE && tagName.equals(temp.getNodeName())) { return getValueOf(temp); } } return null; }
From source file:Main.java
public static Node getTag(Element root, String tagName) { NodeList list = root.getElementsByTagName(tagName); for (int loop = 0; loop < list.getLength(); loop++) { Node node = list.item(loop); System.out.println("nodeName : " + node.getNodeName() + ":::::" + node.getNodeType()); if (node.getNodeName().equals(tagName)) { return node; }//from w w w . ja va2 s . c o m } return null; }
From source file:Main.java
private static void findNodesNamed(Node node, String lookForName, Collection<Node> ret) { if (node.getNodeName().equals(lookForName)) { ret.add(node);//from w ww. java2 s . co m } else { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); ++i) { findNodesNamed(list.item(i), lookForName, ret); } } }
From source file:Main.java
/** * This method gets the child node with the provided name from the * provided start node./*from ww w .j av a 2 s . c o m*/ * @param start The Parent node to scan children. * @param nodeName The name of the node that we're looking for. * @return The Node with name: nodeName, whose parent is the start node. * * @author <a href='mailto:intere@gmail.com'>Eric Internicola</a> */ public static Node getChildNode(Node start, String nodeName) { Node child = null; NodeList children = start.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); if (nodeName.equals(n.getNodeName())) { child = n; break; } } return child; }