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

/**
 * Returns an attribute of the specified tag with the name provided.
 *
 * @param node// w  ww .  j  a  v  a2 s .  c o  m
 * @param name
 * @return The attribute if its defined, or null.
 */
public static String getAttribute(Node node, String name, String defVal) {
    Node att = node.getAttributes().getNamedItem(name);
    return att == null ? defVal : att.getNodeValue();
}

From source file:Main.java

public static String getAttributeValue(Node node, String str) {
    if (node == null || str == null) {
        return null;
    }/*from w w w .j  a  v a2s  .c  o  m*/
    Node namedItem = node.getAttributes().getNamedItem(str);
    return namedItem != null ? namedItem.getNodeValue() : null;
}

From source file:Main.java

@SuppressWarnings("finally")
public static String getType(String relativePath, String nodeName) {
    try {/*from   ww  w  . j  av  a2s  . c o  m*/
        DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = dFactory.newDocumentBuilder();
        Document doc;
        doc = builder.parse(new File(path + relativePath));

        NodeList nl = doc.getElementsByTagName(nodeName);
        Node classNode = nl.item(0).getFirstChild();
        nodeString = classNode.getNodeValue().trim();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        return nodeString;
    }
}

From source file:Main.java

/**
 * Returns all attributes of the given XML node as a list of name=value strings.
 * Mostly just for debugging.//from   w w w . j a  v  a 2s .  com
 * @param node
 * @return
 */
public static List<String> getAttributes(Node node) {
    List<String> result = new ArrayList<String>();
    NamedNodeMap attrs = node.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node attrNode = attrs.item(i);
        result.add(attrNode.getNodeName() + "=" + attrNode.getNodeValue());
    }
    return result;
}

From source file:Main.java

public static String getCharttype() {
    try {// www  .  j a v  a 2  s  . c o  m
        DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = dFactory.newDocumentBuilder();
        Document doc = builder.parse(new File(configPath));

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

From source file:Main.java

public static String getAttribute(Node node, String name) {
    NamedNodeMap attributes = node.getAttributes();
    Node attrNode = attributes.getNamedItem(name);
    if (attrNode != null)
        return attrNode.getNodeValue();
    return null;/*from ww w  . j a  va 2 s  . c  om*/
}

From source file:Main.java

public static String getChildValue(Node node) throws DOMException {
    Node child = node.getFirstChild();
    if (child != null) {
        String val = child.getNodeValue();
        if (val.toUpperCase().startsWith("[CDATA")) {
            val = val.substring(7, val.length() - 2);
        }// w ww .j  a  v  a  2s . c om
        return val;
    } else
        return "NULL";
}

From source file:Main.java

public static String getPath(Node node) {
    NamedNodeMap nodeMap = node.getAttributes();
    Node pathNode = nodeMap.getNamedItem("path");
    if (pathNode != null) {
        return pathNode.getNodeValue();
    } else/*from w  ww  . j ava  2s.  c  o m*/
        return null;
}

From source file:Main.java

public static String getNodeAttribute(Node node, String name) {
    NamedNodeMap map = node.getAttributes();

    Node n = map.getNamedItem(name);
    if (n != null) {
        return n.getNodeValue();
    }/*from  www.ja v a2 s  . com*/
    return null;
}

From source file:Main.java

public static Object getBean(String filePath) {
    try {/* w  w w. j  a v  a2 s .  c o m*/
        DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = dFactory.newDocumentBuilder();
        Document doc;
        doc = builder.parse(new File(filePath));

        NodeList nl = doc.getElementsByTagName("className");
        Node classNode = nl.item(0).getFirstChild();
        String cName = classNode.getNodeValue();
        System.out.println(cName);
        Class c = Class.forName(cName);
        Object obj = c.newInstance();
        return obj;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}