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:grandroid.geo.MapRoute.java

public int getDurationValue(Document doc) {
    NodeList nl1 = doc.getElementsByTagName("duration");
    Node node1 = nl1.item(nl1.getLength() - 1);
    NodeList nl2 = node1.getChildNodes();
    Node node2 = nl2.item(getNodeIndex(nl2, "value"));
    Log.i("DurationValue", node2.getTextContent());
    return Integer.parseInt(node2.getTextContent());
}

From source file:grandroid.geo.MapRoute.java

public int getDistanceValue(Document doc) {
    NodeList nl1 = doc.getElementsByTagName("distance");
    Node node1 = nl1.item(nl1.getLength() - 1);
    NodeList nl2 = node1.getChildNodes();
    Node node2 = nl2.item(getNodeIndex(nl2, "value"));
    Log.i("DistanceValue", node2.getTextContent());
    return Integer.parseInt(node2.getTextContent());
}

From source file:com.puppycrawl.tools.checkstyle.internal.XdocsPagesTest.java

private static void validateParentSection(String fileName, String sectionName, Node subSection) {
    final String expected;

    if (hasParentModule(sectionName)) {
        expected = "TreeWalker";
    } else {/*from w w  w.j a  v  a 2 s.  c  o m*/
        expected = "Checker";
    }

    Assert.assertEquals(fileName + " section '" + sectionName + "' should have matching parent", expected,
            subSection.getTextContent().trim());
}

From source file:com.example.apis.ifashion.WOEIDUtils.java

private void parseLocationLines(Document srcDoc, String name) {
    NodeList nodeList = srcDoc.getElementsByTagName(name);
    if (nodeList.getLength() > 0) {
        Node node = nodeList.item(0);
        mParsedResult.put(name, node.getTextContent());
    }//from w ww.j a  va2  s  .c  o  m
}

From source file:com.phildatoon.weather.WOEIDUtils.java

private String getFirstMatchingWOEID(Document srcDoc) {
    MyLog.d("get first matching WOEID");

    try {/* w  w w. j a  v a  2 s  . c o m*/

        mParsedResult = new HashMap<String, String>();
        for (int i = 1; i <= 4; i++) {
            String name = "line" + i;
            parseLocationLines(srcDoc, name);
        }

        NodeList nodeListDescription = srcDoc.getElementsByTagName("woeid");
        if (nodeListDescription.getLength() > 0) {
            Node node = nodeListDescription.item(0);
            return node.getTextContent();
        } else {
            return WOEID_NOT_FOUND;
        }

    } catch (Exception e) {
        e.printStackTrace();
        return WOEID_NOT_FOUND;
    }
}

From source file:di.uniba.it.tee2.extraction.TemporalExtractor.java

public TaggedText process(String text) throws Exception {
    Date currentTime = Calendar.getInstance(TimeZone.getDefault()).getTime();
    TaggedText taggedText = new TaggedText();
    text = StringEscapeUtils.escapeXml11(text);
    taggedText.setText(text);// ww w  .j av a  2s .co  m
    String timemlOutput = heidelTagger.process(text, currentTime);
    taggedText.setTaggedText(timemlOutput);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    org.w3c.dom.Document doc = builder.parse(new InputSource(new StringReader(timemlOutput)));

    StringBuilder sb = new StringBuilder();
    NodeList timemlNodes = doc.getElementsByTagName("TimeML");
    for (int i = 0; i < timemlNodes.getLength(); i++) {
        NodeList childs = timemlNodes.item(i).getChildNodes();
        for (int j = 0; j < childs.getLength(); j++) {
            Node child = childs.item(j);
            if (child.getNodeType() == Node.TEXT_NODE) {
                sb.append(child.getTextContent());
            } else if (child.getNodeName().equals("TIMEX3")) {
                String timeText = child.getTextContent();
                String timeValueString = child.getAttributes().getNamedItem("value").getNodeValue();
                String normalizedTime = null;
                try {
                    normalizedTime = TEEUtils.normalizeTime(timeValueString);
                } catch (Exception ex) {
                    //logger.log(Level.WARNING, "Error to normalize time: ", ex);
                }
                if (normalizedTime != null) {
                    TimeEvent event = new TimeEvent(sb.length(), sb.length() + timeText.length(),
                            normalizedTime);
                    event.setEventString(timeText);
                    taggedText.getEvents().add(event);
                }
                sb.append(timeText);
            }
            //VERBOSE
            //System.out.println(child.getNodeType() + "\t" + child.getNodeName() + "\t" + child.getTextContent());
            //System.out.println();
        }
    }
    taggedText.setText(sb.toString());
    return taggedText;
}

From source file:org.ambraproject.search.service.DummySOLRMessageSender.java

/**
 * Send a DOM Document message./*from   www  .j a  v  a 2 s .  co m*/
 * @param destination URL of the destination "activemq:plos.pmc" for example.
 * @param body Message body,
 */
public void sendMessage(String destination, Document body) {
    if (indexQueue.equals(destination) || indexPublishQueue.equals(destination)) {
        try {
            //We just want to confirm that SOLR gets something, so lets just index article ID and eIssn

            SolrInputDocument sid = new SolrInputDocument();

            Node res = XPathSingleNodeQuery(body,
                    "//article/front/article-meta/article-id[@pub-id-type='doi']/text()");
            sid.addField("id", res.getTextContent());

            res = XPathSingleNodeQuery(body, "//article/front/journal-meta/issn[@pub-type='epub']/text()");
            sid.addField("eissn", res.getTextContent());

            solrServer.add(sid);
            solrServer.commit();

        } catch (Exception ex) {
            throw new RuntimeException(ex.getMessage(), ex);
        }
    }
}

From source file:lv.semti.Thesaurus.struct.Phrase.java

public Phrase(Node piemNode, String lemma) {
    text = null;/*from  w ww  .j a v  a 2 s  .co  m*/
    grammar = null;
    subsenses = null;
    NodeList fields = piemNode.getChildNodes();
    for (int i = 0; i < fields.getLength(); i++) {
        Node field = fields.item(i);
        String fieldname = field.getNodeName();
        if (fieldname.equals("t"))
            text = field.getTextContent();
        else if (fieldname.equals("gram"))
            grammar = new Gram(field, lemma);
        else if (fieldname.equals("n")) {
            if (subsenses == null)
                subsenses = new LinkedList<Sense>();
            subsenses.add(new Sense(field, lemma));
        } else if (!fieldname.equals("#text")) // Text nodes here are ignored.
            System.err.printf("piem entry field %s not processed\n", fieldname);
    }
}

From source file:org.hdiv.config.xml.ValidationBeanDefinitionParser.java

protected void doParse(Element element, BeanDefinitionBuilder bean) {

    String componentType = element.getAttribute("componentType");

    if (StringUtils.hasText(componentType)) {
        bean.addPropertyValue("componentType", componentType);

    }/*from www  . jav a  2s. c o m*/

    NodeList list = element.getChildNodes();

    for (int i = 0; i < list.getLength(); i++) {
        Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            if (node.getLocalName().equalsIgnoreCase("acceptedPattern")) {

                String value = node.getTextContent();
                if (StringUtils.hasText(value)) {
                    bean.addPropertyValue("acceptedPattern", value);
                }
            }

            if (node.getLocalName().equalsIgnoreCase("rejectedPattern")) {

                String value = node.getTextContent();
                if (StringUtils.hasText(value)) {
                    bean.addPropertyValue("rejectedPattern", value);
                }
            }
        }
    }

}

From source file:com.intuit.karate.ScriptValue.java

public String getAsString() {
    switch (type) {
    case NULL:/*from w  w  w  . ja  va2s. c  om*/
        return null;
    case XML:
        Node node = getValue(Node.class);
        if (node.getTextContent() != null) {
            return node.getTextContent();
        } else {
            return node.getNodeValue();
        }
    case INPUT_STREAM:
        try {
            return IOUtils.toString(getValue(InputStream.class), "utf-8");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    case BSON_DOCUMENT:
        return ((BsonDocument) value).toJson();
    default:
        return value.toString();
    }
}