List of usage examples for org.w3c.dom Node getNodeName
public String getNodeName();
From source file:Main.java
public static Element getChildElement(Element elem, String name) { NodeList nodes = elem.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name)) { return (Element) node; }/*w w w. j av a 2 s .c o m*/ } return null; }
From source file:Main.java
/** * Method selectNodeByName./*from w w w. j a v a 2 s . c o m*/ * * @param node * @param nodeName * @return Node * <p/> * Purpose: given a node & tag name, returns a single node that matches. * Useful when it is known that a particular node will only have a single * node of a particular tag name. */ public static Node selectNodeByName(Node node, String nodeName) { Node nodeToReturn = null; int i = 0; // get all the child nodes NodeList currNodes = node.getChildNodes(); int length = currNodes.getLength(); // search for an occurence that matches nodeName provided while ((i < length) && (nodeToReturn == null)) { Node thisNode = currNodes.item(i); if (thisNode.getNodeName().equals(nodeName)) { nodeToReturn = thisNode; } i++; } return nodeToReturn; }
From source file:Main.java
public static String getLocalName(Node node) { if (node.getPrefix() == null) return node.getNodeName(); else//from ww w . j av a 2s.c om return node.getLocalName(); }
From source file:Main.java
public static Element getLastChild(Element parent, String name) { Element child = null;//from w w w . j av a 2 s . c o m NodeList nl = parent.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) { child = (Element) n; } } return child; }
From source file:Main.java
/** Gets the text information associated with the given DOM element. */ public static String getText(final Element el) { final NodeList nodes = el.getChildNodes(); final int len = nodes.getLength(); for (int i = 0; i < len; i++) { final Node node = nodes.item(i); if ("#text".equals(node.getNodeName())) return node.getNodeValue(); }/*from w w w . j av a 2 s .co m*/ return null; }
From source file:Main.java
private static boolean nodeNameMatch(Node node, Collection desiredNames) { return (desiredNames.contains(node.getNodeName()) || desiredNames.contains(node.getLocalName())); }
From source file:Main.java
public static Node getChildWithTagName(final Node node, String name) { Node r = null;//w w w. ja va2 s . c om for (Node n : iterate(node.getChildNodes())) { if (n.getNodeName().equals(name)) { r = n; break; } } return r; }
From source file:Main.java
/** * This is an ugly hack, there must be a nicer way to do it. * Using getPrefix doesn't work because it stops us from getting * xmlns: attributes, which is what I'm using this for. Using * getNamespace doesn't seem to work on xmlns attributes either. * Trims the prefix on the map key./*from www. j av a 2s .com*/ * @param element the element from which to retrieve the attributes. * @param prefix the prefix of the attributes to retrieve * @return a Map containing the attributes names and their values. */ public static Map getAttributesWithPrefix(Element element, String prefix) { Map result = new HashMap(); prefix += ":"; NamedNodeMap attributes = element.getAttributes(); if (attributes == null) return result; for (int i = 0; i != attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNodeName().startsWith(prefix)) { result.put(attribute.getNodeName().substring(prefix.length()), attribute.getNodeValue()); } } return result; }
From source file:Main.java
/** * Returns the first XML child tag with the specified name. * * @param node The node to search children of * @param name The name of the node to search for, case-sensitive. * @return The child with the specified name, or null if none exists. */// w w w . ja va2 s.c o m public static Node getChildNode(Node node, String name) { Node child = node.getFirstChild(); while (child != null) { if (child.getNodeName().equals(name)) { return child; } child = child.getNextSibling(); } return null; }
From source file:Main.java
public static Element getFirstChild(Element parent, String name) { NodeList nl = parent.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) { return (Element) n; }/*from w w w . ja va2s.c om*/ } return null; }