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

static public String getAttributeValue(Node node, String name) {
    Node attr = getAttribute(node, name);
    return (attr != null) ? attr.getNodeValue() : null;
}

From source file:Main.java

private static boolean elementIsRedundant(Element element) {
    if (element.hasAttributes())
        return false;
    if (!element.hasChildNodes())
        return true;
    NodeList children = element.getChildNodes();
    int childrenCount = children.getLength();
    for (int i = 0; i < childrenCount; ++i) {
        Node child = children.item(i);
        String value = child.getNodeValue();
        if (value != null && !value.matches("\\s*")) {
            return false; // Found non-whitespace text
        }//from   w  ww  .  j  ava2 s  .  c  om
    }
    return true;
}

From source file:Main.java

public static String getNodeContents(Node parentNode) {
    StringBuilder sb = new StringBuilder();

    NodeList childNodes = parentNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        String nodeValue = node.getNodeValue();
        if (nodeValue != null) {
            sb.append(nodeValue);/* w ww. j a  v a 2 s  .com*/
        }
    }

    return sb.toString();
}

From source file:Main.java

public static void copyAttributes(Node from, Node to) {
    NamedNodeMap map = from.getAttributes();
    for (int i = 0; i < map.getLength(); i++) {
        Node attr = map.item(i);
        addAttribute(to, attr.getNodeName(), attr.getNodeValue());
    }/*from   ww  w. j  a  va 2s. c o m*/
}

From source file:Main.java

/**
 * Converts {@link NamedNodeMap} to a {@link LinkedHashMap}&lt;String,String&gt;.
 * @param _nodeMap node map/*from  w w  w  . j a va2  s  . co  m*/
 * @return {@link LinkedHashMap}, maybe empty but never null
 */
public static Map<String, String> convertToAttributeMap(NamedNodeMap _nodeMap) {
    Map<String, String> map = new LinkedHashMap<>();
    for (int i = 0; i < _nodeMap.getLength(); i++) {
        Node node = _nodeMap.item(i);
        map.put(node.getNodeName(), node.getNodeValue());
    }
    return map;
}

From source file:Main.java

public static String getAttribute(Node node, String key) {
    Node namedItem = node.getAttributes().getNamedItem(key);
    return namedItem != null ? namedItem.getNodeValue() : null;
}

From source file:Main.java

public static String getAttributeValue(final Element base, final String name) {

    // get attribute of this element...
    NamedNodeMap mapAttributes = base.getAttributes();
    Node node = mapAttributes.getNamedItem(name);
    if (node != null) {
        return node.getNodeValue();
    }/*from w w  w.j av  a2 s.  c om*/
    return null;
}

From source file:Main.java

public static String getStringValue(NamedNodeMap values, String name, String defaultValue) {
    Node node = values.getNamedItem(name);
    return node == null ? defaultValue : node.getNodeValue();
}

From source file:Main.java

public static void stepThrough(Node start) {
    System.out.println(start.getNodeName() + " = " + start.getNodeValue());

    if (start.getNodeType() == Element.ELEMENT_NODE) {
        NamedNodeMap startAttr = start.getAttributes();
        for (int i = 0; i < startAttr.getLength(); i++) {
            Node attr = startAttr.item(i);
            System.out.println(" Attribute: " + attr.getNodeName() + " = " + attr.getNodeValue());
        }/*from   w  w  w  . j  av a  2 s . c om*/
    }

    for (Node child = start.getFirstChild(); child != null; child = child.getNextSibling()) {
        stepThrough(child);
    }
}

From source file:Main.java

public static String getBrandName() {
    try {//ww w. j  a v  a 2s.c  o m
        DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = dFactory.newDocumentBuilder();
        Document doc = builder.parse(new File("configTV.xml"));

        NodeList nl = doc.getElementsByTagName("Name");
        Node classNode = nl.item(0).getFirstChild();
        String Name = classNode.getNodeValue().trim();
        return Name;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}