Example usage for org.w3c.dom Node getNodeValue

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

Introduction

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

Prototype

public String getNodeValue() throws DOMException;

Source Link

Document

The value of this node, depending on its type; see the table 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  w w w.  ja  v  a2 s .com*/
    }

    return value;
}

From source file:Main.java

public static String get_inner_text(Node node) {
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); ++i) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.TEXT_NODE)
            return child.getNodeValue();
        if (child instanceof Text)
            return ((Text) child).getData();
        /*if (child instanceof TextNode)
           return ((TextNode)child).getData();*/
    }//  w  w  w .  j av a 2  s .co m
    return null;
}

From source file:Main.java

public static String getAttribute(String attribute, Node node) {
    Node attributeNode = node.getAttributes().getNamedItem(attribute);

    if (attributeNode != null)
        return attributeNode.getNodeValue().trim();

    return null;//from w  w  w . ja  v a  2 s . c o  m
}

From source file:Main.java

/**
 * @param n Node to examine//from   w w w .j a v a2 s . c o  m
 * @param attr Attribute to look for
 * @param def Default value to return if attribute is not present
 * @return if the Node contains the named Attribute, the value, if not, the def parameter
 */
public static String getAttributeIgnoreCase(Node n, String attr, String def) {
    NamedNodeMap attrs = n.getAttributes();
    if (attrs == null)
        return def;
    for (int i = 0; i < attrs.getLength(); i++) {
        Node ret = attrs.item(i);
        if (ret.getNodeName().equalsIgnoreCase(attr))
            return ret.getNodeValue();
    }
    return def;
}

From source file:Main.java

public static String getNamespaceURI(final Document doc, final String ns) {
    NamedNodeMap attr = doc.getDocumentElement().getAttributes();
    for (int i = 0; i < attr.getLength(); i++) {
        Node attrNode = attr.item(i);
        if (attrNode.getNodeName().indexOf(ns) != -1) {
            return (attrNode.getNodeValue());
        }/*from ww w.  j a  v a  2  s  .  co m*/
    }
    return null;
}

From source file:Main.java

public static String getAttribute(NamedNodeMap namedNodeMap, String name) {
    Node node = namedNodeMap.getNamedItem(name);
    if (node == null) {
        return null;
    }/*  w ww.  j a  va2s. c  o  m*/
    return node.getNodeValue();
}

From source file:Main.java

public static String getAttributeValue(Node node, String attrName) {
    if (node == null)
        return null;
    NamedNodeMap attrs = node.getAttributes();
    if (attrs == null)
        return null;
    Node attrNode = attrs.getNamedItem(attrName);
    if (attrNode == null)
        return null;
    return attrNode.getNodeValue();
}

From source file:Main.java

public static void setAllIdentityAttribute(Document document, String attributeValue) {
    NodeList propertyList = document.getElementsByTagName("Property");
    for (int i = 0; i < propertyList.getLength(); i++) {
        Node node = propertyList.item(i);
        for (int j = 0; j < node.getAttributes().getLength(); j++) {
            Node attribute = node.getAttributes().item(j);
            if (attribute.getNodeName().equals("name") && attribute.getNodeValue().equals(attributeValue)) {
                Element element = (Element) node;
                element.setAttribute("isIdentity", "true");
            }/*from w w  w  .ja  v  a  2 s .co  m*/
        }
    }
}

From source file:Main.java

public static final Node getSubNodeById(Node n, String id) {
    int i;//from w w  w  . jav a2s .  c om
    NodeList children;
    Node childnode;

    if (n == null) {
        return null;
    }

    children = n.getChildNodes();

    for (i = 0; i < children.getLength(); i++) {
        childnode = children.item(i);
        NamedNodeMap nnm = childnode.getAttributes();
        if (nnm != null) {
            Node attr = nnm.getNamedItem("id");
            if (attr != null && id.equals(attr.getNodeValue())) {
                return childnode;
            }
        }

        childnode = getSubNodeById(childnode, id);
        if (childnode != null) {
            return childnode;
        }
    }
    return null;
}

From source file:Main.java

/**
 * Returns the value of the first child node of the given node, and asserts
 * that the child node is a Text node./*from   www  . j a va2 s .  c o m*/
 * 
 * @param node a node containing a single Text child node
 * @return the value of the child Text node
 */
public static String getChildText(Node node) {
    Node child = node.getFirstChild();
    assert (child.getNodeType() == Node.TEXT_NODE);
    return child.getNodeValue();
}