List of usage examples for org.w3c.dom Node getNodeName
public String getNodeName();
From source file:Main.java
public static Element findNextElement(Node current, boolean sameName) { String name = null;// ww w . j a va 2s. c o m if (sameName) { name = current.getNodeName(); } int type = Node.ELEMENT_NODE; return (Element) getNext(current, name, type); }
From source file:Main.java
public static Node getNext(Node current, boolean sameName) { String name = null;/*from ww w . j a v a 2 s . c o m*/ if (sameName) { name = current.getNodeName(); } int type = current.getNodeType(); return getNext(current, name, type); }
From source file:Main.java
public static Element findPreviousElement(Node current, boolean sameName) { String name = null;/*from w ww . ja v a 2s . c o m*/ if (sameName) { name = current.getNodeName(); } int type = Node.ELEMENT_NODE; return (Element) getPrevious(current, name, type); }
From source file:Main.java
static public Element selectSingleElement(Element element, String xpathExpression) throws XPathExpressionException { if (xpathExpression.indexOf("/") == -1) { NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(xpathExpression)) { return (Element) node; }/*from ww w.ja v a2 s. co m*/ } // NodeList nodes = element.getElementsByTagName(xpathExpression); // if (nodes.getLength() > 0) { // return (Element) nodes.item(0); // } else { return null; // } } else { XPath xpath = XPathFactory.newInstance().newXPath(); Element node = (Element) xpath.evaluate(xpathExpression, element, XPathConstants.NODE); return node; } }
From source file:Main.java
/** * Get the first child element with a specified name. * If the starting node is a Document, use the document element * as the starting point. Only first-generation children of the * starting node are searched.//from w ww . j a v a2 s . c om * @param node the starting node. * @param name the name of the child to find. * @return the first child element with the specified name, or null * if the starting node is null or if no child with the name exists. */ public static Element getFirstNamedChild(Node node, String name) { if (node == null) return null; if (node instanceof Document) node = ((Document) node).getDocumentElement(); if (!(node instanceof Element)) return null; Node child = node.getFirstChild(); while (child != null) { if ((child instanceof Element) && child.getNodeName().equals(name)) { return (Element) child; } child = child.getNextSibling(); } return null; }
From source file:Main.java
public static String retrieveNodeAsString(Node node) { String nodeStr = new String("<"); nodeStr += node.getNodeName() + internal; if (node.hasAttributes()) { NamedNodeMap attrs = node.getAttributes(); // add the attrubite name-value pairs for (int i = 0; i < attrs.getLength(); i++) { Node a = attrs.item(i); nodeStr += a.getNodeName() + "=" + a.getNodeValue() + internal; }/*from www. j ava2s.co m*/ } if (node.hasChildNodes()) { nodeStr += ">\n"; NodeList ns = node.getChildNodes(); for (int i = 0; i < ns.getLength(); i++) { nodeStr += logXMLSubNode(ns.item(i), 1); } nodeStr += "<" + node.getNodeName() + "/>\n"; } else { nodeStr += "/>\n"; } return nodeStr; }
From source file:Main.java
private static void printNode(NodeList nodeList, int level) { level++;//from w w w . j a v a2 s.c o m if (nodeList != null && nodeList.getLength() > 0) { for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { System.out.println(node.getNodeName() + "[" + level + "]"); printNode(node.getChildNodes(), level); // how depth is it? if (level > depthOfXML) depthOfXML = level; } } } }
From source file:Main.java
/** Look for Element node of given name. * * <p>Checks the node itself and its siblings for an {@link Element}. * Does not descent down the 'child' links. * * @param node Node where to start./*w ww. ja v a2 s.c o m*/ * @param name Name of the node to look for. * @return Returns node, the next matching sibling, or <code>null</code>. */ private static final Element findElementByName(Node node, final String name) { while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name)) return (Element) node; node = node.getNextSibling(); } return null; }
From source file:Main.java
public static Element findNextElement(final Node current, final boolean sameName) { String name = null;// www. j a v a2s .c om if (sameName) { name = current.getNodeName(); } int type = Node.ELEMENT_NODE; return (Element) getNext(current, name, type); }
From source file:Main.java
public static Node getNext(final Node current, final boolean sameName) { String name = null;//from www. j av a 2 s . c om if (sameName) { name = current.getNodeName(); } int type = current.getNodeType(); return getNext(current, name, type); }