Java XML Child Get by Name getChildDoubleByName(Node node, String nodeName, double errValue)

Here you can find the source of getChildDoubleByName(Node node, String nodeName, double errValue)

Description

get Child Double By Name

License

CDDL license

Parameter

Parameter Description
node Node
nodeName String
errValue double

Return

double

Declaration

public static double getChildDoubleByName(Node node, String nodeName, double errValue) 

Method Source Code

//package com.java2s;
/*/*  w  w w.  j a  v a 2  s .co m*/
Copyright (c) 2013 eBay, Inc.
This program is licensed under the terms of the eBay Common Development and
Distribution License (CDDL) Version 1.0 (the "License") and any subsequent  version 
thereof released by eBay.  The then-current version of the License can be found 
at http://www.opensource.org/licenses/cddl1.php and in the eBaySDKLicense file that 
is under the eBay SDK ../docs directory.
*/

import org.w3c.dom.Node;

public class Main {
    /**
     *
     * @param node Node
     * @param nodeName String
     * @param errValue double
     * @return double
     */
    public static double getChildDoubleByName(Node node, String nodeName, double errValue) {
        String s = getChildStringByName(node, nodeName, "");
        if (s.length() > 0)
            return Double.parseDouble(s);
        return errValue;
    }

    /**
     *
     * @param node Node
     * @param nodeName String
     * @param errValue String
     * @return String
     */
    public static String getChildStringByName(Node node, String nodeName, String errValue) {
        Node nd = getChildByName(node, nodeName);
        if (nd != null) {
            Node fnd = nd.getFirstChild();
            if (fnd != null)
                return fnd.getNodeValue();
        }
        return errValue;
    }

    /**
     * Find node by name.
     * @param node Node
     * @param nodeName String
     * @return Node
     */
    public static Node getChildByName(Node node, String nodeName) {
        org.w3c.dom.NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node c = children.item(i);
            if (c.getNodeName().equals(nodeName))
                return c;
        }
        return null;
    }
}

Related

  1. getChildByTagName(Element element, String tag)
  2. getChildByTagName(Element element, String tagName)
  3. getChildByTagName(Node parent, String tagname)
  4. getChildData(Element e, String tag)
  5. getChildDouble(final Element parent, final String name)
  6. getChildElemByTagName(Element parent, String tagName)
  7. getChildElement(Element currentNode, String nsURI, String localName)
  8. getChildElement(Element el, String tagName)
  9. getChildElement(Element el, String tagName)