List of usage examples for org.w3c.dom Node getNodeName
public String getNodeName();
From source file:Main.java
/** Get the next sibling with the same name and type *//* www . j a va2 s .c om*/ public static Node getNext(Node current) { String name = current.getNodeName(); int type = current.getNodeType(); return getNext(current, name, type); }
From source file:Main.java
public static Node up(Node node, String element) { while (node != null && node.getNodeName() != null && !node.getNodeName().equalsIgnoreCase(element)) { node = node.getParentNode();/*from ww w. j a v a 2 s. c om*/ } return node; }
From source file:Main.java
public static void stepThrough(Node start) { System.out.println(start.getNodeName() + " = " + start.getNodeValue()); if (start.getNodeType() == Element.ELEMENT_NODE) { NamedNodeMap startAttr = start.getAttributes(); for (int i = 0; i < startAttr.getLength(); i++) { Node attr = startAttr.item(i); System.out.println(" Attribute: " + attr.getNodeName() + " = " + attr.getNodeValue()); }//w w w . java2 s . c om } for (Node child = start.getFirstChild(); child != null; child = child.getNextSibling()) { stepThrough(child); } }
From source file:Main.java
private static String unevaluatedXML(String result, Node node) { String nodeName = node.getNodeName(); String attributes = ""; if (node.hasAttributes()) { NamedNodeMap XMLAttributes = node.getAttributes(); for (int i = 0; i < XMLAttributes.getLength(); i++) {/*from ww w .ja va 2s . co m*/ attributes += " " + XMLAttributes.item(i).getNodeName() + "=\"" + XMLAttributes.item(i).getNodeValue() + "\""; } } if (result.equals("")) return " <" + nodeName + attributes + "/> "; else return " <" + nodeName + attributes + ">" + result + "</" + nodeName + "> "; // add spaces }
From source file:Main.java
public static Node getNamedChild(Node node, String name) { Node retVal = null;// w ww. j av a 2 s . co m NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeName() == name) { retVal = child; } } return retVal; }
From source file:Main.java
/** * @param n Node to examine/* w w w . j a v a2 s. co m*/ * @param attr Attribute to look for * @param def Default value to return if attribute is not present * @return if the Node contains the named Attribute, the value, if not, the def parameter */ public static String getAttributeIgnoreCase(Node n, String attr, String def) { NamedNodeMap attrs = n.getAttributes(); if (attrs == null) return def; for (int i = 0; i < attrs.getLength(); i++) { Node ret = attrs.item(i); if (ret.getNodeName().equalsIgnoreCase(attr)) return ret.getNodeValue(); } return def; }
From source file:Main.java
public static Node findNode(Node parentNode, String key) { NodeList childNodes = parentNode.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNode.getNodeName().equals(key)) { return childNode; }/* w ww.j a v a 2s. c o m*/ } return null; }
From source file:Main.java
public static Node getChildByName(Node parent, String childName) { NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node child = (Node) children.item(i); if (child.getNodeName().equals(childName)) { return child; }/* w w w.ja v a 2 s .com*/ } return null; }
From source file:Main.java
/** * Find node by name.// w ww . j a v a 2 s. c o m * @param node Node * @param nodeName String * @return Node */ public static Node getChildByName(Node node, String nodeName) { org.w3c.dom.NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node c = children.item(i); if (c.getNodeName().equals(nodeName)) return c; } return null; }
From source file:Main.java
public static Node findElementByTag(Set<Node> nodes, String tag) { Node result = null;/* w ww . j a v a 2 s. co m*/ for (Node child : nodes) { if (tag.equals(child.getNodeName())) { result = child; break; } } return result; }