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

StringgetValue(Node node)
get Value
StringBuffer value = new StringBuffer();
if (node != null) {
    int childCount = node.getChildNodes().getLength();
    for (int i = 0; i < childCount; i++) {
        Node childNode = node.getChildNodes().item(i);
        switch (childNode.getNodeType()) {
        case Node.TEXT_NODE:
        case Node.CDATA_SECTION_NODE:
...
StringgetValue(Node node)
get Value
if (node == null) {
    return null;
return getValue(node.getTextContent());
StringgetValue(Node node)
get Value
String val = "";
if (node != null) {
    if (node instanceof Element) {
        val = node.getTextContent();
    } else if (node instanceof Attr) {
        val = ((Attr) node).getValue();
    } else {
        val = node.getNodeValue();
...
StringgetValue(Node node)
Get the value of a node.
NodeList children = node.getChildNodes();
if (children.getLength() == 0) {
    return "";
return children.item(0).getNodeValue();
StringgetValue(Node node, short nodeType)
get Value
switch (nodeType) {
case Node.ELEMENT_NODE:
    return ((Element) node).getTagName();
case Node.TEXT_NODE:
    return ((Text) node).getData();
case Node.PROCESSING_INSTRUCTION_NODE:
    return ((ProcessingInstruction) node).getData();
default:
...
StringgetValue(Node node, short nodeType)
get Value
switch (nodeType) {
case Node.ELEMENT_NODE:
    return ((Element) node).getTagName();
case Node.TEXT_NODE:
    return ((Text) node).getData();
case Node.PROCESSING_INSTRUCTION_NODE:
    return ((ProcessingInstruction) node).getData();
default:
...
StringgetValue(Node node, short nodeType)
get Value
switch (nodeType) {
case Node.ELEMENT_NODE:
    return ((Element) node).getTagName();
case Node.TEXT_NODE:
    return ((Text) node).getData();
case Node.PROCESSING_INSTRUCTION_NODE:
    return ((ProcessingInstruction) node).getData();
default:
...
StringgetValue(Node node, String Tag)
Get Value from XML
if (node == null)
    return "";
NodeList nl = ((Element) node).getElementsByTagName(Tag);
if (nl == null)
    return "";
Element el = (Element) nl.item(0);
if (el == null)
    return "";
...
StringgetValue(Node pNode)
returns a XML node value.
String s = null;
try {
    NodeList nodes = pNode.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        s = ((Node) nodes.item(i)).getNodeValue().trim();
        if (s.equals("") || s.equals("\r"))
            continue;
} catch (Exception ex) {
    throw new Exception(ex.getMessage());
return s;
StringgetValueByElement(Node node)
get Value By Element
List<Node> ref_nodes = getChildRefNode(node);
if (ref_nodes.size() == 1) {
    Node define_node = getDefineRefByName(getRefName(ref_nodes.get(0)), node.getOwnerDocument());
    return getValueByElement(define_node);
} else if (getNodeValue(node) != null) {
    return getNodeValue(node).getTextContent();
} else {
    return "";
...