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 void dumpNodeDetails(Node node) throws Exception {
    NamedNodeMap attributes = node.getAttributes();
    for (int t = 0; t < attributes.getLength(); t++) {
        Node aNode = attributes.item(t);
        log.info("aName = " + aNode.getNodeName() + " : aValue = " + aNode.getNodeValue());
    }/* w w  w  .  jav  a 2s.  c om*/
}

From source file:Main.java

public static String getAttribute(Node node, String name) {
    String value = "";

    NamedNodeMap attributes = node.getAttributes();
    Node attribute = attributes.getNamedItem(name);
    if (attribute != null) {
        value = attribute.getNodeValue();
    }//from w  ww  .ja v a 2s . co m

    return value;
}

From source file:Main.java

public static String getAttributeValue(Node node, String attributeName) {
    Node n = node.getAttributes().getNamedItem(attributeName);
    return (n == null) ? null : n.getNodeValue();
}

From source file:Main.java

private static void serializeAttributeOf(XmlSerializer serializer, Element element) throws IOException {
    NamedNodeMap map = element.getAttributes();
    for (int i = 0; i < map.getLength(); i++) {
        Node attr = map.item(i);
        serializer.attribute(null, attr.getNodeName(), attr.getNodeValue());
    }/*from   w w  w  . j a v a2s  .c  o m*/
}

From source file:Main.java

/**
 * Get an attribute.//w  w w  . ja  va2 s .  c o m
 * 
 * @param node node
 * @param attr attribute name
 * @return value
 */
public static String getAttr(Node node, String attr) {
    Node attrNode = node.getAttributes().getNamedItem(attr);
    return attrNode != null ? attrNode.getNodeValue() : "";
}

From source file:Main.java

/**
 * Get an attribute.//www . java2s  .c o m
 * 
 * @param node node
 * @param attr attribute name
 * @return value or null
 */
public static String getAttrOrNull(Node node, String attr) {
    Node attrNode = node.getAttributes().getNamedItem(attr);
    return attrNode != null ? attrNode.getNodeValue() : null;
}

From source file:Main.java

public static String getStartDateFromLineNode(Node linenode) {
    String date = "";
    Node t1 = linenode.getAttributes().getNamedItem("startdate");
    if (t1 != null)
        date = t1.getNodeValue();
    else//from w  ww . j  a v a 2s .  c  om
        date = linenode.getOwnerDocument().getElementsByTagName("startdate").item(0).getFirstChild()
                .getNodeValue();
    return date;
}

From source file:Main.java

public static String getPrefix(org.w3c.dom.Element el, String ns) {
    NamedNodeMap atts = el.getAttributes();
    for (int i = 0; i < atts.getLength(); i++) {
        Node node = atts.item(i);
        String name = node.getNodeName();
        if (ns.equals(node.getNodeValue())
                && (name != null && (XMLNAMESPACE.equals(name) || name.startsWith(XMLNAMESPACE + ":")))) {
            return node.getPrefix();
        }//  w  w  w.  j  a v  a 2  s  .c o  m
    }
    return null;
}

From source file:Main.java

public static String getElementValueByTagName(Element root, String tagName) {
    NodeList nodes = root.getElementsByTagName(tagName);
    if (nodes != null) {
        Node node = nodes.item(0).getFirstChild();
        if (node != null) {
            return node.getNodeValue();
        } else {//from   w ww.j a v a  2 s .c om
            return null;
        }
    } else {
        return null;
    }
}

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  .  j a v  a 2  s  .  c o  m*/
    throw new IllegalArgumentException("Node is not a text Node");
}