Example usage for org.w3c.dom Node getTextContent

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

Introduction

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

Prototype

public String getTextContent() throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:Main.java

public static String getOptionalAttributeValue(NamedNodeMap attrs, String name) {

    Node namedItem = attrs.getNamedItem(name);
    if (namedItem == null) {
        return "";
    } else {/* w  w  w  .  j  a v a 2  s .  c o  m*/
        return namedItem.getTextContent();
    }
}

From source file:Main.java

public static String peekValue(final Document doc, final String xpathExpression)
        throws XPathExpressionException {
    final XPath xPath = XPF.newXPath();
    final XPathExpression expression = xPath.compile(xpathExpression);

    final Node node = (Node) expression.evaluate(doc, XPathConstants.NODE);
    final String result = (node != null) ? node.getTextContent() : null;
    return result;
}

From source file:Main.java

public static String getRequestNameFull(String xml)
        throws ParserConfigurationException, SAXException, IOException {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(new InputSource(new StringReader(xml)));

    NodeList nodeList = document.getDocumentElement().getChildNodes();
    Node reqName = document.getElementsByTagName("request-name").item(0);
    System.out.println(reqName.getTextContent());

    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        System.out.println(i + "--" + node);
        if (node instanceof Element) {
            NodeList childNodes = node.getChildNodes();
            for (int j = 0; j < childNodes.getLength(); j++) {
                Node cNode = childNodes.item(j);
                System.out.println(i + "--" + j + "--" + cNode);
                if (cNode instanceof Element) {
                    String content = cNode.getLastChild().getTextContent().trim();
                    System.out.println(i + "--" + j + "--" + content);
                }//from w ww .ja v  a  2 s .c o  m
            }
        }
    }
    /*
     * Do the parsing for reqname
     */
    return reqName.getTextContent();
}

From source file:Main.java

/**
 * Extract the text content of a named node from a list of nodes.
 * Returns null if the node is not found.
 *
 * @param map attribute node map/* ww w  .j  a  v  a  2s.c om*/
 * @param attrName name of the attribute to extract from the list
 * @return found node text or null if not found
 */
public static String getAttributeTextFromList(final NamedNodeMap map, final String attrName) {

    String text = null;

    if (map != null) {
        final Node node = getAttributeFromList(map, attrName);

        if (node != null) {
            text = node.getTextContent();
        }
    }

    return text;
}

From source file:Main.java

public static String getTextContent(Node parent, String tagName) {
    Node node = findChildWithTagName(parent, tagName);
    if (node != null) {
        return node.getTextContent();
    } else {//ww  w . jav a 2s. c  om
        return null;
    }
}

From source file:Main.java

private static String getDate(Node node) {
    String date = "";
    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node curNode = nodeList.item(i);
        if ("date".equalsIgnoreCase(curNode.getNodeName())) {
            date = curNode.getTextContent().replace("\"", "");
            break;
        }/*www  .j  a  v  a  2 s . c  o  m*/
    }

    return date;
}

From source file:Main.java

public static String getTextContent(Document doc, String tagName) {
    Node node = getFirstElementByTagName(doc, tagName);
    if (node != null) {
        return node.getTextContent();
    } else {/*from ww w.j  a v  a  2  s . co m*/
        return null;
    }
}

From source file:Main.java

/**
 * Extract the text content of a named node from a list of nodes.
 * Returns null if the node is not found.
 *
 * @param nodeList a list of nodes/*  w  w  w. ja  v  a 2 s  .  c  o  m*/
 * @param nodeName name of the node to extract from the list
 * @return found node text or null if not found
 */
public static String getNodeTextFromList(final NodeList nodeList, final String nodeName) {

    String text = null;

    if (nodeList != null) {
        final Node node = getNodeFromList(nodeList, nodeName);

        if (node != null) {
            text = node.getTextContent();
        }
    }

    return text;
}

From source file:Main.java

private static String getShiftId(Node node) {
    String name = "";
    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node curNode = nodeList.item(i);
        if ("shiftId".equalsIgnoreCase(curNode.getNodeName())) {
            name = curNode.getTextContent().replace("\"", "");
            break;
        }/*from   w ww.ja v a  2  s.com*/
    }

    return name;
}

From source file:Main.java

static String stringElement(Element row, String name) {
    final NodeList childNodes = row.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        final Node node = childNodes.item(i);
        if (name.equals(node.getLocalName())) {
            String result = node.getTextContent();
            // If content is not plain text then returns name of
            // first child tag
            if (result == null && node.hasChildNodes()) {
                result = node.getFirstChild().getLocalName();
            }//from  w  w  w  .  j a v  a 2  s  . com
            return result;
        }
    }
    return null;
}