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 boolean isText(Node node) {
    return node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE;
}

From source file:Main.java

public static boolean isAttribute(Node node) {
    return node.getNodeType() == Node.ATTRIBUTE_NODE;
}

From source file:Main.java

public static void removeAll(Node node, short nodeType, String name) {
    if (node.getNodeType() == nodeType && (name == null || node.getNodeName().equals(name))) {
        node.getParentNode().removeChild(node);
    } else {//from   w ww .ja  v a2s . c o  m
        NodeList list = node.getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
            removeAll(list.item(i), nodeType, name);
        }
    }
}

From source file:Main.java

public static String getTagName(Node labelNode) {
    if (labelNode.getNodeType() == Node.ELEMENT_NODE) {
        return labelNode.getNodeName();
    }//from w  ww .  j  a v a  2  s  . co  m
    return null;
}

From source file:Main.java

public static boolean isElement(Node node) {
    short nodeType = node.getNodeType();
    if (Node.ELEMENT_NODE == nodeType || Node.DOCUMENT_NODE == nodeType) {
        return true;
    }/*from  ww  w.  j  a va2 s . com*/
    return false;
}

From source file:Main.java

public static Document getDocument(Node node) {
    if (node.getNodeType() == Node.DOCUMENT_NODE) {
        return (Document) node;
    }//from   ww  w  . j a va  2  s.  com
    return node.getOwnerDocument();
}

From source file:Main.java

public static boolean isElement(Node n) {
    return (n.getNodeType() == Node.ELEMENT_NODE);
}

From source file:Main.java

protected static Node getNodeIfDocument(Node node) {
    if (node.getNodeType() == Node.DOCUMENT_NODE) {
        return ((Document) node).getDocumentElement();
    } else {//from   w  w w .  j  a  v  a2  s  .c  o m
        return node;
    }
}

From source file:Main.java

private static void print(Node e, String tab) {

    if (e.getNodeType() == Node.TEXT_NODE) {
        System.out.println(tab + e.getNodeValue());
        return;/*  w w  w  .ja va 2 s  . co  m*/
    }

    System.out.print(tab + e.getNodeName());

    NamedNodeMap as = e.getAttributes();
    if (as != null && as.getLength() > 0) {
        System.out.print(" attributes=[");
        for (int i = 0; i < as.getLength(); i++)
            System.out.print((i == 0 ? "" : ", ") + as.item(i));
        System.out.print("]");
    }
    System.out.println();

    if (e.getNodeValue() != null)
        System.out.println(tab + " " + e.getNodeValue());

    NodeList childs = e.getChildNodes();
    for (int i = 0; i < childs.getLength(); i++)
        print(childs.item(i), tab + " ");
}

From source file:Main.java

private static void printNote(NodeList nodeList, int depth) {
    for (int count = 0; count < nodeList.getLength(); count++) {
        Node tempNode = nodeList.item(count);
        if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
            System.out.println(depth + "Node Name =" + tempNode.getNodeName());
            System.out.println(depth + "Node Value =" + tempNode.getTextContent());
            if (tempNode.hasAttributes()) {
                NamedNodeMap nodeMap = tempNode.getAttributes();
                for (int i = 0; i < nodeMap.getLength(); i++) {
                    Node node = nodeMap.item(i);
                    System.out.println("attr name : " + node.getNodeName());
                    System.out.println("attr value : " + node.getNodeValue());
                }/*from w  w  w. jav a2  s  . c  o  m*/
            }
            if (tempNode.hasChildNodes()) {
                printNote(tempNode.getChildNodes(), depth + 1);
            }
            System.out.println(depth + "Node Name =" + tempNode.getNodeName());
        }
    }
}