Java XML Element Get by Name getElementFloatValue(Document document, Element parent, String element)

Here you can find the source of getElementFloatValue(Document document, Element parent, String element)

Description

get Element Float Value

License

Apache License

Declaration

public static float getElementFloatValue(Document document, Element parent, String element) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static float getElementFloatValue(Document document, Element parent, String element) {
        return Float.parseFloat(getElementStringValue(document, parent, element));
    }//  ww  w  . j a v a  2s .  c  om

    public static String getElementStringValue(Document document, Element parent, String element) {
        NodeList nl = parent.getElementsByTagName(element);
        if (nl.getLength() == 0) {
            return "";
        }

        Node n = nl.item(0).getFirstChild();
        if (n == null) {
            return "";
        }

        return n.getNodeValue();
    }
}

Related

  1. getElementByTagName(Element aParent, String aName)
  2. getElementByTagName(Element parent, String elementName)
  3. getElementByTagName(Element parent, String elementName)
  4. getElementByTagNameWithParents(Element n, String... elementName)
  5. getElementDateValue(Document document, Element parent, String string)
  6. getElements(Element parent, String localName)
  7. getElements(Element parent, String localname, String namespaceURI)
  8. getElements(Element parent, String tagName)
  9. getElements(Element parent, String tagName)