Java Utililty Methods XML Node Value

List of utility methods to do XML Node Value

Description

The list of methods to do XML Node Value are organized into topic(s).

Method

StringgetNodeValue(Node node)
Returns the value of given node
String retval = "";
try {
    Node firstChild = node.getFirstChild();
    if (firstChild != null)
        retval = firstChild.getNodeValue();
} catch (Exception e) {
    return "";
return retval;
StringgetNodeValue(Node node, String name, boolean trim)
get Node Value
String retValue = null;
NodeList element = ((Element) node).getElementsByTagName(name);
if (element.getLength() > 0) {
    NodeList valueNodeList = ((Element) element.item(0)).getChildNodes();
    if (valueNodeList.getLength() > 0) {
        retValue = valueNodeList.item(0).getNodeValue();
return (trim && (retValue != null)) ? retValue.trim() : retValue;
StringgetNodeValue(Node node, String name, String defaultVal, int index)
Gets a value from a named child node
NodeList nl = node.getChildNodes();
if (nl.getLength() == 0)
    return defaultVal;
Node n = getNodeFromNodeList(nl, name, index);
if (n == null)
    return defaultVal;
n = n.getChildNodes().item(0);
if (n == null)
...
StringgetNodeValue(Node node, String nodeKey)
get Node Value
Node opt_item = node.getAttributes().getNamedItem(nodeKey);
if (opt_item != null) {
    Matcher nameMatcher = attrExtractor.matcher(opt_item.toString());
    if (nameMatcher.find()) {
        return nameMatcher.group(1);
return null;
...
StringgetNodeValue(Node nodeXML)
Return the value of the node nodeXML
return nodeXML.getChildNodes().item(0).getNodeValue();
StringgetNodeValue(org.w3c.dom.Node node)
get Node Value
return node.getFirstChild().getNodeValue();
StringgetNodeValue(org.w3c.dom.Node node)
get Node Value
for (int i = 0; i < node.getChildNodes().getLength(); i++) {
    if (node.getChildNodes().item(i).getNodeType() == Node.TEXT_NODE)
        return node.getChildNodes().item(i).getNodeValue();
return "";
DategetNodeValueAsDate(Node node)
Gets the node value as date.
if (node == null)
    return null;
NamedNodeMap attrs = node.getAttributes();
Node attr = attrs.getNamedItem("DateTimeFormat");
String format = attr.getNodeValue().trim();
node = node.getFirstChild();
if (node != null) {
    String date = node.getNodeValue().trim();
...
longgetNodeValueAsLong(Node node)
Gets the node value as long.
if (node != null) {
    node = node.getFirstChild();
    if (node != null)
        return Long.parseLong(node.getNodeValue());
return -1;
longgetNodeValueAsTime(Node node)
Gets the node value as time.
if (node == null)
    return -1;
NamedNodeMap attrs = node.getAttributes();
Node attr = attrs.getNamedItem("Unit");
int factor = 1;
String unit = attr.getNodeValue();
if (unit.equals("sec")) {
    factor = 1000;
...