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:Main.java

/**
 *  Gets the node value as float./*from w w  w .  j  av a  2  s  .  c o  m*/
 *
 *@param  node              Description of the Parameter
 *@return                   The nodeValueAsFloat value
 *@exception  DOMException  Description of the Exception
 */
public final static float getNodeValueAsFloat(Node node) throws DOMException {
    if (node != null) {
        node = node.getFirstChild();
        if (node != null)
            return Float.parseFloat(node.getNodeValue());
    }
    return -1;
}

From source file:Main.java

/**
 *  Gets the node value as double./*from   w  ww  . j ava 2  s  .  c o m*/
 *
 *@param  node              Description of the Parameter
 *@return                   The nodeValueAsDouble value
 *@exception  DOMException  Description of the Exception
 */
public final static double getNodeValueAsDouble(Node node) throws DOMException {
    if (node != null) {
        node = node.getFirstChild();
        if (node != null)
            return Double.parseDouble(node.getNodeValue());
    }
    return -1;
}

From source file:Main.java

/**
 *  Gets the node value as long./*  ww w.j  av  a  2 s . c om*/
 *
 *@param  node              Description of the Parameter
 *@return                   The nodeValueAsLong value
 *@exception  DOMException  Description of the Exception
 */
public final static long getNodeValueAsLong(Node node) throws DOMException {
    if (node != null) {
        node = node.getFirstChild();
        if (node != null)
            return Long.parseLong(node.getNodeValue());
    }
    return -1;
}

From source file:Main.java

static String getTextValue(Node node) throws SAXException {
    Node textNode = node.getFirstChild();
    if (textNode == null)
        return "";
    if (textNode.getNodeType() != Node.TEXT_NODE)
        throw new SAXException("No text value found for <" + node.getNodeName() + "> node");
    return textNode.getNodeValue();
}

From source file:Main.java

/**
 *  Gets the node value as int.//from   www.  j  a v  a  2  s . c o  m
 *
 *@param  node              Description of the Parameter
 *@return                   The nodeValueAsInt value
 *@exception  DOMException  Description of the Exception
 */
public final static int getNodeValueAsInt(Node node) throws DOMException {
    if (node != null) {
        node = node.getFirstChild();
        if (node != null)
            return Integer.parseInt(node.getNodeValue());
    }
    return -1;
}

From source file:Main.java

/**
 *   Find the first child node matching the given tag name. Only searches 
 *   1st-level children; not a recursive search. Null if not found.
 *//*from  ww  w.  j ava  2  s  .  co m*/
public static Node findChildNodeMatching(Node root, String tagName, short nodeType) {
    Node childNode = root.getFirstChild();
    while (childNode != null) {
        if (childNode.getNodeType() == nodeType) {
            if (tagName.equals(childNode.getNodeName())) {
                return childNode;
            }
        }

        childNode = childNode.getNextSibling();
    }

    return null;
}

From source file:Main.java

/** Look for child node of given name.
 *
 *  @param parent Node where to start./*from w  w w . java  2 s  .c o  m*/
 *  @param name Name of the node to look for.
 *  @return Returns Element or <code>null</code>.
 */
public static final Element getChildElement(final Node parent, final String name) {
    return findElementByName(parent.getFirstChild(), name);
}

From source file:Main.java

/**
 *  Gets the node value as boolean./*from   w w  w.ja  v  a2 s  .co  m*/
 *
 *@param  node              Description of the Parameter
 *@return                   The nodeValueAsBoolean value
 *@exception  DOMException  Description of the Exception
 */
public final static boolean getNodeValueAsBoolean(Node node) throws DOMException {
    if (node != null) {
        node = node.getFirstChild();
        return node.getNodeValue() != null && (node.getNodeValue().equalsIgnoreCase("YES")
                || node.getNodeValue().equalsIgnoreCase("TRUE"));
    }

    return false;
}

From source file:Main.java

/** Finds and returns the first child element node. */
public static Element getFirstChildElement(Node parent) {

    // search for node
    Node child = parent.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            return (Element) child;
        }//from w  w  w .j a  v  a  2  s  .  c o  m
        child = child.getNextSibling();
    }

    // not found
    return null;

}

From source file:Main.java

public static String getNodeValue(Node node) {
    String ret = "";
    if (node != null) {
        for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling())
            ret = (new StringBuilder(String.valueOf(ret))).append(child.getNodeValue()).toString();

    }//www.j a v a2  s . c  o m
    return ret;
}