Example usage for org.w3c.dom Node getNodeType

List of usage examples for org.w3c.dom Node getNodeType

Introduction

In this page you can find the example usage for org.w3c.dom Node getNodeType.

Prototype

public short getNodeType();

Source Link

Document

A code representing the type of the underlying object, as defined above.

Usage

From source file:Main.java

public static String getText(Node node) {
    String value = "";

    NodeList children = node.getChildNodes();
    for (int k = 0; k < children.getLength(); k++) {
        Node child = children.item(k);
        if (child.getNodeType() == Node.TEXT_NODE) {
            value = child.getNodeValue();
        }//from   ww  w .j ava  2 s .  c o  m
    }

    return value;
}

From source file:Utils.java

/**
 * /*from  w  w w  .  j a  va 2 s. c  o m*/
 */
public static String getElementText(Element element) {
    StringBuffer buffer = new StringBuffer();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) {
            buffer.append(node.getNodeValue());
        }
    }
    return buffer.toString();
}

From source file:Main.java

public static String getDirectTextContent(Node aNode) {
    String result = "";
    NodeList nodeList = aNode.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node aSubNode = nodeList.item(i);
        if (aSubNode.getNodeType() == Node.TEXT_NODE) {
            result += aSubNode.getNodeValue();
        }//from  ww w  . j  a  v  a2  s  .  c o  m
    }
    return result;
}

From source file:Main.java

public static Node findSibling(Node node, String tagName) {
    Node n = node;
    while (n != null && n.getNodeType() != Node.ELEMENT_NODE && !n.getNodeName().equals(tagName))
        n = n.getNextSibling();//w  w  w . j  av  a2 s .co  m
    return n;
}

From source file:Main.java

public static List<Element> childs(Node node) {
    NodeList children = node.getChildNodes();
    List<Element> result = new LinkedList<Element>();
    for (int i = 0; i < children.getLength(); i++) {
        Node c = children.item(i);
        if (c.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }//  w  ww .j  a va2  s . c  o  m
        result.add((Element) c);
    }
    return result;
}

From source file:Main.java

public static Node GetSimpleTagNode(Document doc, String tag) {
    NodeList nList2 = doc.getElementsByTagName(tag);
    for (int temp = 0; temp < nList2.getLength(); temp++) {
        Node nNode2 = nList2.item(temp);
        if (nNode2.getNodeType() == Node.ELEMENT_NODE) {
            return nNode2;
        } // end if nnode.getnodetype()
    } //end for int temp
    return null;/*from   www  .  j  av a  2 s .  co  m*/
}

From source file:Main.java

private static short getNodeType(Node node) {
    return (node != null ? node.getNodeType() : -1);
}

From source file:Main.java

public static List<Element> getElementCollectionFromDocument(Document document, String tagName) {
    List<Element> res = new LinkedList<Element>();
    NodeList entries = document.getElementsByTagName(tagName);
    for (int i = 0; i < entries.getLength(); i++) {
        Node entry = entries.item(i);
        if (entry.getNodeType() == Node.ELEMENT_NODE) {
            res.add((Element) entry);
        }/*  w w w .  j av  a  2s  . c  o  m*/
    }
    return res;
}

From source file:Main.java

public static List<Element> getElementCollectionByTagName(Element element, String tagName) {
    List<Element> result = new LinkedList<Element>();
    NodeList nodeList = element.getElementsByTagName(tagName);
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            result.add((Element) node);
        }// w ww  . j a  v  a  2  s. c o  m
    }
    return result;
}

From source file:Main.java

public static Element getPrevSibling(Element e) {
    Node n = e.getPreviousSibling();
    while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
        n = n.getPreviousSibling();/*from   w  w w.  j a  v  a 2s. co  m*/
    return (Element) n;
}