Java Utililty Methods XML Element Get Value

List of utility methods to do XML Element Get Value

Description

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

Method

StringgetType(Element elementType)
get XSI type attribute
return elementType.getAttribute("xsi:type");
ElementgetUniqueElement(Element root, String elementName)
get Unique Element
NodeList list = root.getElementsByTagName(elementName);
return (Element) list.item(0);
ElementgetUniqueSubnode(Element rootNode, String name)
get Unique Subnode
Element result = null;
NodeList childNodes = rootNode.getChildNodes();
for (int i = 0; i < childNodes.getLength(); ++i) {
    Node aNode = childNodes.item(i);
    if (aNode.getNodeType() == Node.ELEMENT_NODE) {
        Element el = (Element) aNode;
        if (name.equals(el.getNodeName())) {
            if (null == result) {
...
StringgetValue(Element e, String tagName)
Given a person element, must get the element specified by the tagName, then must traverse that Node to get the value.
try {
    NodeList elements = e.getElementsByTagName(tagName);
    Node node = elements.item(0);
    NodeList nodes = node.getChildNodes();
    String s;
    for (int i = 0; i < nodes.getLength(); i++) {
        s = ((Node) nodes.item(i)).getNodeValue().trim();
        if (s.equals("") || s.equals("\r")) {
...
StringgetValue(Element el)
get Value
if (el != null) {
    NodeList nodes = el.getChildNodes();
    StringBuffer sb = new StringBuffer();
    int length = nodes.getLength();
    for (int i = 0; i < length; ++i) {
        Node node = nodes.item(i);
        String s = null;
        s = node.getNodeValue();
...
StringgetValue(Element element)
get Value
NodeList l = element.getChildNodes();
StringBuffer s = new StringBuffer();
for (int i = 0; i < l.getLength(); i++) {
    switch (l.item(i).getNodeType()) {
    case Node.TEXT_NODE:
    case Node.CDATA_SECTION_NODE:
        s.append(l.item(i).getNodeValue());
return s.toString();
StringgetValue(Element element)
Get the text value for the specified element.
if (element != null) {
    Node dataNode = element.getFirstChild();
    if (dataNode != null) {
        return ((Text) dataNode).getData();
return null;
StringgetValue(Element element)
get Value
return element.getChildNodes().item(0).getNodeValue();
StringgetValue(Element element, String tag)
get Value
String textValue = null;
NodeList nodes = element.getElementsByTagName(tag);
if (nodes != null && nodes.getLength() > 0) {
    Element childElement = (Element) nodes.item(0);
    Node node = childElement.getFirstChild();
    if (node != null) {
        textValue = node.getNodeValue();
return textValue;
StringgetValue(Element pElement)
returns a XML element value.
String s = null;
try {
    NodeList nodes = pElement.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;