List of usage examples for org.w3c.dom Node ELEMENT_NODE
short ELEMENT_NODE
To view the source code for org.w3c.dom Node ELEMENT_NODE.
Click Source Link
Element
. From source file:Main.java
public static int indexOf(NodeList nodeList, String tagName, int startIdx) { for (int i = startIdx; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) { if (node.getNodeName().equals(tagName)) { return i; }/*from www.j a va 2 s . co m*/ } } return -1; }
From source file:Main.java
public static Element getChildElement(String tagName, Element element) { NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i);/*from ww w . j av a 2 s. co m*/ if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(tagName)) { return (Element) n; } } return null; }
From source file:Main.java
public static List<Element> getChildElementsNS(Element parent, String uri) { List<Element> ret = new ArrayList<Element>(); NodeList childList = parent.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { if (childList.item(i).getNodeType() != Node.ELEMENT_NODE) continue; Element child = (Element) childList.item(i); if (child.getNamespaceURI().equals(uri)) ret.add(child);/* w w w . j a v a 2 s. c o m*/ } return ret; }
From source file:Main.java
/** * Get the next sibling element of the specified element, null if it has no other siblings. * /*from w ww.java2 s . co m*/ * @param element The element to search siblings for. * @return The next sibling element, null if it has none. */ public static Element getNextSibling(Element element) { if (element == null) return null; Node node = element.getNextSibling(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) return (Element) node; node = node.getNextSibling(); } return null; }
From source file:Main.java
/** * Returns the child element with the specified tagName for the specified * parent element.// w ww. ja va 2 s.co m * @param parent The parent whose child we're looking for. * @param tagName the name of the child to find * @return The child with the specified name or null if no such child was * found. * @throws NullPointerException if parent or tagName are null */ public static Element findChild(Element parent, String tagName) { if (parent == null || tagName == null) throw new NullPointerException( "Parent or tagname were null! " + "parent = " + parent + "; tagName = " + tagName); NodeList nodes = parent.getChildNodes(); Node node; int len = nodes.getLength(); for (int i = 0; i < len; i++) { node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && ((Element) node).getNodeName().equals(tagName)) return (Element) node; } return null; }
From source file:Main.java
public static Element getFirstChildElementByLocalName(Element parentElem, String localName) { Node child = parentElem.getFirstChild(); while (child != null) { if ((child.getNodeType() == Node.ELEMENT_NODE) && getLocalName(child).equals(localName)) { return (Element) child; }// w w w . j a v a2 s. c o m child = child.getNextSibling(); } return null; }
From source file:Main.java
static public List<Element> getChildElementList(Element root) { List<Element> list = new ArrayList<>(); NodeList nodes = root.getChildNodes(); int i, size = nodes.getLength(); Node node;/*from w ww. j a va 2s .c o m*/ for (i = 0; i < size; i++) { node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) list.add((Element) node); } return list; }
From source file:Main.java
public static Element getNextSiblingElement(Node node) { if (node == null) return null; Node nextSibling = node.getNextSibling(); while ((nextSibling != null) && (nextSibling.getNodeType() != Node.ELEMENT_NODE)) nextSibling = nextSibling.getNextSibling(); if ((nextSibling != null) && (nextSibling.getNodeType() == Node.ELEMENT_NODE)) return (Element) nextSibling; return null;// w ww . j ava2 s . c o m }
From source file:Main.java
/** * Get the previous sibling element of the specified element, null if it has no previous other siblings. * /* ww w . ja va2s . co m*/ * @param element The element to search siblings for. * @return The previous sibling element, null if it has none. */ public static Element getPrevSibling(Element element) { if (element == null) return null; Node node = element.getPreviousSibling(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) return (Element) node; node = node.getPreviousSibling(); } return null; }
From source file:Main.java
/** * Get element Node from NodeList./*w w w . ja va 2 s . c o m*/ * * @param nodeList * NodeList. * @return Element Node */ public static Node getNodeFromNodeList(NodeList nodeList) { if (nodeList != null && nodeList.getLength() > 0) { for (int i = 0; i < nodeList.getLength(); i++) { if (nodeList.item(i).getNodeType() == Node.ELEMENT_NODE) { return nodeList.item(i); } } } return null; }