Android Utililty Methods XML Element Child Get

List of utility methods to do XML Element Child Get

Description

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

Method

ElementfindNextSiblingElement(Element current)
find Next Sibling Element
org.w3c.dom.Node ret = current.getNextSibling();
while (ret != null) {
    if (ret instanceof Element) {
        return (Element) ret;
    ret = ret.getNextSibling();
return null;
...
ElementGetElement(Element root, String namespaceUri, String name, boolean throwIfNotFound)
Get Element
NodeList nodes = root.getElementsByTagNameNS(namespaceUri, name);
if (nodes.getLength() > 0)
    return (Element) nodes.item(0);
else {
    if (throwIfNotFound)
        throw new Exception(
                String.format(
                        "A node with name '%s' in namespace '%s' was not found.",
...
ArrayListgetListContent(Element listElement, String listItemName, String listItemNamespace)
Get list content for the given XML element, of the form content...
if (listElement == null) {
    throw new IllegalArgumentException("listElement cannot be null");
if (listItemName == null || listItemName.length() == 0) {
    throw new IllegalArgumentException(
            "listItemName cannot be null or empty");
if (listItemNamespace == null) {
...
StringgetStringFromXml(Element validate, Boolean hasHeader)
get String From Xml
final String header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = null;
try {
    transformer = transFactory.newTransformer();
} catch (TransformerConfigurationException e) {
    e.printStackTrace();
StringWriter buffer = new StringWriter();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
        "yes");
try {
    transformer.transform(new DOMSource(validate),
            new StreamResult(buffer));
} catch (TransformerException e) {
    e.printStackTrace();
String s = buffer.toString();
if (hasHeader) {
    return header + s;
return s;