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:com.swetha.easypark.GetDirections.java

public String getDistanceText(Document doc) {
    NodeList nl1 = doc.getElementsByTagName("distance");
    Node node1 = nl1.item(nl1.getLength() - 1);
    NodeList nl2 = node1.getChildNodes();
    Node node2 = nl2.item(getNodeIndex(nl2, "text"));
    Log.i("DistanceText", node2.getTextContent());
    return node2.getTextContent();
}

From source file:gov.nih.nci.cacis.ip.mirthconnect.CanonicalModelProcessorDocRouterIntegrationTest.java

@Test
public void invokeSOAP() throws Exception {

    final Node res = invoke(ADDRESS, SoapTransportFactory.TRANSPORT_ID, getValidMessage().getBytes());
    assertNotNull(res);/*ww w.  j  a v  a2  s.  c  o m*/
    LOG.info("Echo response: " + res.getTextContent());

}

From source file:cn.lambdalib.cgui.loader.xml.CGUIDocLoader.java

private void parseComponent(Node n, Widget target) {
    NodeList nl = n.getChildNodes();
    Map<String, String> propertyMap = new HashMap();
    String clazz = ((Element) n).getAttribute("class");
    for (int i = 0; i < nl.getLength(); ++i) {
        Node n2 = nl.item(i);
        propertyMap.put(n2.getNodeName(), n2.getTextContent());
    }/*from  www .  jav  a  2  s  .com*/
    if (clazz == null) {
        throw new RuntimeException("didn't find one of the component class when parsing CGUI document.");
    }

    Component c = null;
    try {
        c = (Component) Class.forName(clazz).newInstance();
    } catch (Exception e) {
        LambdaLib.log.error("An error occured trying to instantiate class " + clazz, e);
    }

    c.fromPropertyMap(propertyMap);
    target.addComponent(c);
    if (c.name.equals("Transform")) {
        target.transform = (Transform) c;
    }
}

From source file:org.jmxtrans.embedded.spring.EmbeddedJmxTransBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    builder.setRole(BeanDefinition.ROLE_APPLICATION);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

    if (element.hasAttribute(IGNORE_CONFIGURATION_NOT_FOUND_ATTRIBUTE)) {
        builder.addPropertyValue("ignoreConfigurationNotFound",
                element.getAttribute(IGNORE_CONFIGURATION_NOT_FOUND_ATTRIBUTE));
    }//from w w w .ja  v a 2  s  .  c  o  m
    List<String> configurationUrls = new ArrayList<String>();
    if (element.hasAttribute(CONFIGURATION_ATTRIBUTE)) {
        String configurationUrl = element.getAttribute(CONFIGURATION_ATTRIBUTE);
        logger.debug("Add configuration from attribute {}", configurationUrl);
        configurationUrls.add(configurationUrl);
    }

    NodeList configurationNodeList = element.getElementsByTagNameNS(element.getNamespaceURI(),
            CONFIGURATION_ATTRIBUTE);
    for (int i = 0; i < configurationNodeList.getLength(); i++) {
        Node node = configurationNodeList.item(i);
        if (node instanceof Element) {
            String configurationUrl = node.getTextContent();
            logger.debug("Add configuration from attribute {}", configurationUrl);
            configurationUrls.add(configurationUrl);
        } else {
            throw new EmbeddedJmxTransException("Invalid configuration child element " + node);
        }

    }
    builder.addPropertyValue("configurationUrls", configurationUrls);
}

From source file:me.willowcheng.makerthings.model.OpenHABLinkedPage.java

public OpenHABLinkedPage(Node startNode) {
    if (startNode.hasChildNodes()) {
        NodeList childNodes = startNode.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node childNode = childNodes.item(i);
            if (childNode.getNodeName().equals("id")) {
                this.setId(childNode.getTextContent());
            } else if (childNode.getNodeName().equals("title")) {
                this.setTitle(childNode.getTextContent());
            } else if (childNode.getNodeName().equals("icon")) {
                this.setIcon(childNode.getTextContent());
            } else if (childNode.getNodeName().equals("link")) {
                this.setLink(childNode.getTextContent());
            }//from   w w w  . j  a v  a2  s. co  m
        }
    }
}

From source file:com.cisco.dvbu.ps.common.adapters.config.AdapterConfig.java

private HashMap<String, String> getElementsByTagName(String sTag, Element eElement) {
    String value = null;/*  w  w  w.  j a v a  2s. com*/
    HashMap<String, String> map = new HashMap<String, String>();
    NodeList nlList = eElement.getElementsByTagName(sTag);
    if (nlList != null && nlList.item(0) != null) {
        NodeList nodes = nlList.item(0).getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            map.put(node.getNodeName(), node.getTextContent());
        }
    }
    return map;
}

From source file:com.github.xdcrafts.flower.spring.impl.xml.SyncFlowBeanDefinitionHandler.java

protected void doParse(Element element, BeanDefinitionBuilder bean) {
    final ManagedList<Object> actions = new ManagedList<>();
    final NodeList actionNodes = element.getElementsByTagName("*");
    if (actionNodes != null && actionNodes.getLength() != 0) {
        for (int i = 0; i < actionNodes.getLength(); i++) {
            final Node node = actionNodes.item(i);
            final String type = node.getLocalName();
            if (type.equalsIgnoreCase("method")) {
                actions.add(node.getTextContent());
            } else if (type.equalsIgnoreCase("action")) {
                actions.add(new RuntimeBeanReference(node.getTextContent()));
            } else {
                throw new IllegalArgumentException("Unknown element type: " + type);
            }/*from  w  ww . j av  a  2s.c o m*/
        }
    }
    bean.addPropertyValue("actions", actions);
}

From source file:eu.scape_project.planning.evaluation.evaluators.XmlExtractor.java

public HashMap<String, String> extractValues(Document xml, String path) {
    try {/*from   w  w w .j  a va2s .co m*/
        HashMap<String, String> resultMap = new HashMap<String, String>();

        XPathFactory factory = XPathFactory.newInstance();

        XPath xpath = factory.newXPath();
        xpath.setNamespaceContext(namespaceContext);
        XPathExpression expr = xpath.compile(path);

        NodeList list = (NodeList) expr.evaluate(xml, XPathConstants.NODESET);
        if (list != null) {
            for (int i = 0; i < list.getLength(); i++) {
                Node n = list.item(i);
                String content = n.getTextContent();
                if (content != null) {
                    resultMap.put(n.getLocalName(), content);
                }
            }
        }
        return resultMap;
    } catch (Exception e) {
        log.error("Could not parse XML " + " searching for path " + path + ": " + e.getMessage(), e);
        return null;
    }
}

From source file:eu.apenet.dpt.utils.util.extendxsl.EdmQualityCheckerCall.java

@Override
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
    NodeInfo nodeInfo = (NodeInfo) sequences[0].head();
    NodeOverNodeInfo nodeOverNodeInfo = NodeOverNodeInfo.wrap(nodeInfo);
    boolean hasNoIdentifier;

    //get dc:identifier information from edm:ProvidedCHO
    String identifier = "";
    NodeList childNodes = nodeOverNodeInfo.getChildNodes();

    //if dc:identifier exists, set variable, else increment counter
    hasNoIdentifier = true;/*from   w ww. ja  v a2 s.c  o m*/
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getLocalName() != null && node.getLocalName().equals("identifier")
                && node.getTextContent() != null && StringUtils.isNotBlank(node.getTextContent())) {
            hasNoIdentifier = false;
            identifier = node.getTextContent();
        }
    }
    if (hasNoIdentifier) {
        counterNoUnitid++;
    }

    //collect all dc:identifier values in Map for detection of duplicates
    if (StringUtils.isNotBlank(identifier)) {
        Integer numOccurrence = identifiers.get(identifier);
        if (numOccurrence == null) {
            //first count
            identifiers.put(identifier, 1);
        } else {
            identifiers.put(identifier, numOccurrence + 1);
        }
    }
    return StringValue.makeStringValue("");
}

From source file:com.jkoolcloud.tnt4j.streams.transform.FuncGetObjectName.java

/**
 * Resolves desired object name from provided fully qualified object name. Fully qualified object name can be
 * provided as {@link String}, {@link org.w3c.dom.Node} or {@link org.w3c.dom.NodeList} (first node item containing
 * object name).//from  ww  w  . j a  va  2  s  . c om
 * <p>
 * function arguments sequence:
 * <ul>
 * <li>1 - fully qualified object name. Required.</li>
 * <li>2 - resolution options: DEFAULT, BEFORE, AFTER, REPLACE, SECTION, FULL. Optional.</li>
 * <li>3 - search symbols. Optional.</li>
 * <li>4 - replacement symbols. Optional</li>
 * </ul>
 *
 * @param args
 *            function arguments list
 * @return object name resolved form provided fully qualified object name
 *
 * @see org.w3c.dom.Node
 * @see org.w3c.dom.NodeList
 */
@Override
@SuppressWarnings("rawtypes")
public Object evaluate(List args) {
    Object param = CollectionUtils.isEmpty(args) ? null : args.get(0);

    if (param == null) {
        return param;
    }

    String objectFQN = null;
    if (param instanceof String) {
        objectFQN = (String) param;
    } else if (param instanceof Node) {
        objectFQN = ((Node) param).getTextContent();
    } else if (param instanceof NodeList) {
        NodeList nodes = (NodeList) param;

        if (nodes.getLength() > 0) {
            Node node = nodes.item(0);
            objectFQN = node.getTextContent();
        }
    }

    if (StringUtils.isEmpty(objectFQN)) {
        return objectFQN;
    }

    return resolveObjectName(objectFQN, args);
}