Java Utililty Methods XML Element Get

List of utility methods to do XML Element Get

Description

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

Method

BooleangetElementAsBoolean(Element e, String name)
get Element As Boolean
return getElementAsBoolean(e, name, false);
FloatgetElementAsFloat(Element e, String name, Float dft)
get Element As Float
String num = getElement(e, name);
return num.equals("") ? dft : Float.parseFloat(num);
intgetElementAsInt(Element element)
get Element As Int
return Integer.parseInt(element.getTextContent());
StringgetElementAttributeValue(Document doc, String tagName, String attributeName)
Return the named attribute from the specified element in the (XML) document.
return getAttributeValue(doc.getElementsByTagName(tagName), attributeName);
booleangetElementBooleanValue(Document document, Element parent, String element)
get Element Boolean Value
return Boolean.valueOf(getElementStringValue(document, parent, element)).booleanValue();
ElementgetElementByClass(Element ele, String name)
Get child element by classname
List<Element> list = getElementsByClass(ele, name);
if (list.size() > 0)
    return list.get(0);
return null;
ListgetElementByFilter(Document doc, NodeFilter filter)
get Element By Filter
List<Element> result = new ArrayList<Element>();
DocumentTraversal traversable = (DocumentTraversal) doc;
int whatToShow = NodeFilter.SHOW_ELEMENT;
NodeIterator iterator = traversable.createNodeIterator(doc, whatToShow, filter, true);
Node current = null;
while ((current = iterator.nextNode()) != null) {
    result.add((Element) current);
return result;
ElementgetElementByID(Element el, String id)
get Element By ID
if (el == null)
    return null;
String thisId = el.getAttribute("id");
if (id.equals(thisId))
    return el;
NodeList list = el.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
    Node node = list.item(i);
...
ElementgetElementByID(Element el, String id)
DOCUMENTME
if (el == null) {
    return null;
String thisId = el.getAttribute("id");
if (id.equals(thisId)) {
    return el;
NodeList list = el.getChildNodes();
...
ElementgetElementById(Element element, String id)
get Element By Id
return getElementById(element.getChildNodes(), id);