List of usage examples for org.w3c.dom Node getNodeType
public short getNodeType();
From source file:Main.java
public static boolean isNodeTypeText(Node node) { return node != null && node.getNodeType() == Node.TEXT_NODE; }
From source file:Main.java
/** * Check whether a given XML <code>Node</code> is * an element node./*from w w w.j a v a 2s . c o m*/ * * Sun should've implemented <code>Node.hasType(int)</code>.... * * @param n * @return */ public static final boolean isElementNode(Node n) { return n != null && n.getNodeType() == Node.ELEMENT_NODE; }
From source file:Main.java
public static boolean isElement(Node node) { return node != null && (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.DOCUMENT_NODE); }
From source file:Main.java
private static String ensureExtractTextNodeValue(final Node node) { if (node.getNodeType() == Node.TEXT_NODE) { return node.getNodeValue(); }/*from w w w .jav a2 s. co m*/ throw new IllegalArgumentException("Node is not a text Node"); }
From source file:Main.java
public static Element GetFirstElementChild(Element tag) { Node n = tag.getFirstChild(); while (n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling();/* ww w .j a va 2 s.co m*/ } Element e = (Element) n; return e; }
From source file:Main.java
public static Element getNextElement(Node el) { Node node = el; while (node != null && node.getNodeType() != Node.ELEMENT_NODE) { node = node.getNextSibling();/* w ww .j a va 2 s. c om*/ } return (Element) node; }
From source file:Main.java
/** * Returns a node's first child node that is an element. * @param parent// w w w .j a v a 2s . c o m * @return first child element, or null */ public static Element getFirstChildElement(Node parent) { NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { return (Element) n; } } return null; }
From source file:DOMHelper.java
/** * Gets the owner document of a node./* w w w . j a va 2 s . c o m*/ * * @param node the node * @return the node's document or the node itself if it is a document node * * @throws NullPointerException if {@code node} is {@code null} */ public static Document getOwnerDocument(Node node) { if (node.getNodeType() == Node.DOCUMENT_NODE) return (Document) node; return node.getOwnerDocument(); }
From source file:Main.java
public static String GetFirstInstance(NodeList nList) { for (int i = 0; i < nList.getLength(); i++) { Node nNode = nList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; if (eElement != null) return eElement.getTextContent(); } // end if nnode.getnodetype() } //end for int temp return new String(""); }
From source file:Main.java
public static List<Element> getChildElements(Element elt, String name) { List<Element> list = new ArrayList<Element>(); NodeList nodes = elt.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node child = nodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) if (name.equals(child.getNodeName())) list.add((Element) child); }/*ww w . j ava2 s . c o m*/ return list; }