Example usage for org.w3c.dom Node getFirstChild

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

Introduction

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

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

Usage

From source file:com.zoho.creator.jframework.XMLParser.java

static String getStringValue(Node node, String defaultValue) {
    if (node != null && node.getFirstChild() != null) {
        return node.getFirstChild().getNodeValue();
    }/*w  w  w  . j a  v  a 2s.co  m*/
    return defaultValue;
}

From source file:com.zoho.creator.jframework.XMLParser.java

private static boolean getBooleanValue(Node node, boolean defaultValue) {
    if (node != null && node.getFirstChild() != null) {
        return Boolean.valueOf(node.getFirstChild().getNodeValue());
    }/*from w ww  . jav  a  2  s . co  m*/
    return defaultValue;
}

From source file:it.ciroppina.idol.generic.tunnel.IdolOEMTunnel.java

/**
 * Method that catches response node from xml autnresponse
 * //from w w  w . ja v  a2 s  .  c  om
 * @return a XML Document
 */
@WebMethod(operationName = "getQueryResponse")
public String getQueryResponse(String xml) {
    String result = "";
    Document document = getDocumentFrom(xml);
    if (document == null)
        return xml;

    NodeList response = document.getElementsByTagName("response");
    Node resp = response.item(0);

    result = resp.getFirstChild().getNodeValue();
    return result;
}

From source file:com.oracle.tutorial.jdbc.ProductInformationTable.java

public void populateTable(String fileName)
        throws SQLException, ParserConfigurationException, SAXException, IOException, XPathExpressionException {
    javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
    // factory.setNamespaceAware(true);
    factory.setNamespaceAware(true);/*ww w  . ja  v a 2s .com*/
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(fileName);

    XPathFactory xPathfactory = XPathFactory.newInstance();

    XPath xPath = xPathfactory.newXPath();

    NodeList nodes = (NodeList) xPath.evaluate("/coffee-product-information/item[coffee = 'Columbian']", doc,
            XPathConstants.NODESET);

    for (int i = 0; i < nodes.getLength(); i++) {
        Node currentNode = nodes.item(i);
        // Retrieve the description element

        currentNode.normalize();

        if (currentNode == null) {
            System.out.println("Current node is null");
        }

        //      System.out.println(currentNode.getTextContent());

        Node descriptionNode = (Node) xPath.evaluate("description", currentNode, XPathConstants.NODE);

        if (descriptionNode == null) {
            System.out.println("DescriptionNode is null");
        } else {

            System.out.println(descriptionNode.getTextContent());

            NodeList descriptionNodeChildren = descriptionNode.getChildNodes();
            System.out.println("Description node has " + descriptionNodeChildren.getLength() + " child nodes");
            Node descNodeChild = descriptionNode.getFirstChild();
            System.out.println("Only child node type: " + descNodeChild.getNodeType());
        }

        //      System.out.println("Description: " + descriptionNode.getNodeValue());

        // System.out.println(nodes.item(i).getNodeValue());
    }

}

From source file:com.adaptris.util.XmlUtils.java

/**
 * Method which updates the Text value of a specified Node
 *
 * @param value the new Text value/*from  ww  w  .ja v  a 2 s.c om*/
 * @param n the node to be modified
 * @throws Exception on error.
 */
public void setNodeValue(String value, Node n) throws Exception {
    n.normalize();
    n.getFirstChild().setNodeValue(value);
}

From source file:org.dasein.cloud.opsource.OpSourceMethod.java

public boolean requestResult(String action, Document doc) throws CloudException, InternalException {

    if (wire.isDebugEnabled()) {
        wire.debug(provider.convertDomToString(doc));
    }/*from w  w w  . j  a  va2  s .c o m*/

    String sNS = "";
    try {
        sNS = doc.getDocumentElement().getTagName().substring(0,
                doc.getDocumentElement().getTagName().indexOf(":") + 1);
    } catch (IndexOutOfBoundsException ex) {
    }

    NodeList blocks = doc.getElementsByTagName(sNS + OpSource.RESPONSE_RESULT_TAG);
    if (blocks != null) {
        for (int i = 0; i < blocks.getLength(); i++) {
            Node attr = blocks.item(i);
            if (attr.getFirstChild().getNodeValue().equals(OpSource.RESPONSE_RESULT_SUCCESS_VALUE)) {
                return true;
            }
            if (attr.getFirstChild().getNodeValue().equals(OpSource.RESPONSE_RESULT_ERROR_VALUE)) {
                blocks = doc.getElementsByTagName(sNS + OpSource.RESPONSE_RESULT_DETAIL_TAG);
                if (blocks == null) {
                    throw new CloudException(action + " fails " + "without explaination !!!");
                } else {
                    throw new CloudException(blocks.item(0).getFirstChild().getNodeValue());
                }
            }
        }
    }
    return false;
}

From source file:org.dasein.cloud.opsource.OpSourceMethod.java

public boolean parseRequestResult(String action, Document doc, String resultTag, String resultDetailTag)
        throws CloudException, InternalException {
    if (wire.isDebugEnabled()) {
        wire.debug(provider.convertDomToString(doc));
    }//from   w  ww .j a va2 s  . co  m

    String sNS = "";
    try {
        sNS = doc.getDocumentElement().getTagName().substring(0,
                doc.getDocumentElement().getTagName().indexOf(":") + 1);
    } catch (IndexOutOfBoundsException ex) {
    }
    NodeList blocks = doc.getElementsByTagName(sNS + resultTag);
    if (blocks != null) {
        for (int i = 0; i < blocks.getLength(); i++) {
            Node attr = blocks.item(i);
            if (attr.getFirstChild().getNodeValue().equals(OpSource.RESPONSE_RESULT_SUCCESS_VALUE)) {
                return true;
            }
            if (attr.getFirstChild().getNodeValue().equals(OpSource.RESPONSE_RESULT_ERROR_VALUE)) {
                blocks = doc.getElementsByTagName(sNS + resultDetailTag);
                if (blocks == null) {
                    logger.error(action + " fails " + "without explaination !!!");
                    throw new CloudException(action + " fails " + "without explaination !!!");

                } else {
                    logger.error(blocks.item(0).getFirstChild().getNodeValue());
                    throw new CloudException(blocks.item(0).getFirstChild().getNodeValue());
                }
            }
        }
    }
    return false;
}

From source file:org.dasein.cloud.opsource.OpSourceMethod.java

public boolean parseRequestResultNoError(String action, Document doc, String resultTag, String resultDetailTag)
        throws CloudException, InternalException {
    if (wire.isDebugEnabled()) {
        wire.debug(provider.convertDomToString(doc));
    }/* ww w. j a  v a2s .c  om*/

    String sNS = "";
    try {
        sNS = doc.getDocumentElement().getTagName().substring(0,
                doc.getDocumentElement().getTagName().indexOf(":") + 1);
    } catch (IndexOutOfBoundsException ex) {
    }
    NodeList blocks = doc.getElementsByTagName(sNS + resultTag);
    if (blocks != null) {
        for (int i = 0; i < blocks.getLength(); i++) {
            Node attr = blocks.item(i);
            if (attr.getFirstChild().getNodeValue().equals(OpSource.RESPONSE_RESULT_SUCCESS_VALUE)) {
                return true;
            }
            if (attr.getFirstChild().getNodeValue().equals(OpSource.RESPONSE_RESULT_ERROR_VALUE)) {
                blocks = doc.getElementsByTagName(sNS + resultDetailTag);
                if (blocks == null) {
                    logger.error(action + " fails " + "without explaination !!!");
                    throw new CloudException(action + " fails " + "without explaination !!!");

                } else {
                    logger.trace(blocks.item(0).getFirstChild().getNodeValue());
                    throw new CloudException(blocks.item(0).getFirstChild().getNodeValue());
                }
            }
        }
    }
    return false;
}

From source file:org.dasein.cloud.opsource.OpSourceMethod.java

public String requestResult(String action, Document doc, String resultTag, String resultDetailTag)
        throws CloudException, InternalException {
    if (doc == null) {
        throw new CloudException("Action -> " + action + " failed because request reponse is null");
    }/*w  ww . ja v  a2  s  .  c om*/

    if (wire.isDebugEnabled()) {
        wire.debug(provider.convertDomToString(doc));
    }

    String sNS = "";
    try {
        sNS = doc.getDocumentElement().getTagName().substring(0,
                doc.getDocumentElement().getTagName().indexOf(":") + 1);
    } catch (IndexOutOfBoundsException ex) {
    }
    NodeList blocks = doc.getElementsByTagName(sNS + resultTag);
    if (blocks != null) {
        for (int i = 0; i < blocks.getLength(); i++) {
            Node attr = blocks.item(i);
            if (attr.getFirstChild().getNodeValue().equals(OpSource.RESPONSE_RESULT_SUCCESS_VALUE)) {
                blocks = doc.getElementsByTagName(sNS + resultDetailTag);
                if (blocks == null) {
                    throw new CloudException(action + "  fails " + "without explaination !!!");
                } else {
                    return blocks.item(0).getFirstChild().getNodeValue();
                }
            } else if (attr.getFirstChild().getNodeValue().equals(OpSource.RESPONSE_RESULT_ERROR_VALUE)) {
                blocks = doc.getElementsByTagName(sNS + resultDetailTag);
                if (blocks == null) {
                    throw new CloudException(action + " fails " + "without explaination !!!");
                } else {
                    throw new CloudException(blocks.item(0).getFirstChild().getNodeValue());
                }
            }
        }
    }
    return null;
}

From source file:com.zoho.creator.jframework.XMLParser.java

private static Date getDateValue(Node node, Date defaultValue, String dateFormat) {
    if (node != null && node.getFirstChild() != null) {
        String dateString = node.getFirstChild().getNodeValue();
        Date toReturn = getDateValue(dateString, dateFormat);
        if (toReturn != null) {
            return toReturn;
        }//w w w .j  a va  2  s.  c o m
    }
    return defaultValue;
}