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

StringgetValueFromElement(Element element, String tagName)
Gets the string value of the tag element name passed
NodeList elementNodeList = element.getElementsByTagName(tagName);
if (elementNodeList == null) {
    return "";
} else {
    Element tagElement = (Element) elementNodeList.item(0);
    if (tagElement == null) {
        return "";
    NodeList tagNodeList = tagElement.getChildNodes();
    if (tagNodeList == null || tagNodeList.getLength() == 0) {
        return "";
    return tagNodeList.item(0).getNodeValue();
StringgetValueFromElement(Element element, String tagName)
Gets the string value of the tag element name passed
try {
    NodeList elementNodeList = element.getElementsByTagName(tagName);
    Element tagElement = (Element) elementNodeList.item(0);
    NodeList tagNodeList = tagElement.getChildNodes();
    return ((Node) tagNodeList.item(0)).getNodeValue();
} catch (NullPointerException error) {
    return "";
StringgetWholeText(Element element)
get Whole Text
StringBuilder builder = new StringBuilder();
NodeList nodeList = element.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node instanceof Text)
        builder.append(((Text) node).getWholeText());
    else if (node instanceof Element)
        builder.append(getWholeText((Element) node));
...
BooleangetXmlBoolean(Element element, String name)
get Xml Boolean
String val = getXmlString(element, name);
return Boolean.parseBoolean(val);
StringgetXMLContent(XMLEventReader reader, StartElement element, boolean decodeCharacters)
get XML Content
String rootElementName = getLocalName(element);
StringWriter buffer = new StringWriter(1024);
StartElement pendingElement = null;
String pendingElementName = null;
while (reader.hasNext()) {
    XMLEvent event = reader.nextEvent();
    if (pendingElement != null) {
        boolean skip = false;
...
XmlElementgetXmlElementAnnotation(Field field)
Returns the XmlElement annotation for the given field, if the annotation exists.
for (Annotation annotation : field.getDeclaredAnnotations()) {
    if (annotation instanceof XmlElement) {
        return (XmlElement) annotation;
return null;
XmlElementDeclgetXmlElementDecl(Method method)
Returns annotation XmlElementDecl of the given factory method
XmlElementDecl ret = null;
if (null == method) {
    throw new Exception("method is null");
XmlElementDecl xmlElementDecl = (XmlElementDecl) method.getAnnotation(XmlElementDecl.class);
if (null != xmlElementDecl) {
    ret = xmlElementDecl;
return ret;
StringgetXMLElementTextValue(Element element, String tagName)
Parse the text value of the tag with the specified name.
NodeList nl = element.getElementsByTagName(tagName);
if (nl != null && nl.getLength() > 0) {
    Element el = (Element) nl.item(0);
    return el.getFirstChild().getNodeValue();
return null;
StringgetXMLIdentifier(Element element)
Generates a unique string from the supplied element's name space URI and tag name.
if (element == null)
    throw new NullPointerException("element"); 
return getQualifiedIdentifier(element.getLocalName(), element.getNamespaceURI());
StringgetXMLText(Element element)
Gets the text from an XML element
String text = "";
NodeList nodeList = element.getChildNodes();
for (int index = 0; index < nodeList.getLength(); index++) {
    Node node = nodeList.item(index);
    if (node.getNodeType() == Node.TEXT_NODE)
        text += node.getNodeValue();
    else
        text += getXMLText((Element) node);
...