Android XML Element Child Get GetElement(Element root, String namespaceUri, String name, boolean throwIfNotFound)

Here you can find the source of GetElement(Element root, String namespaceUri, String name, boolean throwIfNotFound)

Description

Get Element

Declaration

public static Element GetElement(Element root, String namespaceUri,
            String name, boolean throwIfNotFound) throws Exception 

Method Source Code

//package com.java2s;

import org.w3c.dom.*;

public class Main {
    public static Element GetElement(Element root, String namespaceUri,
            String name, boolean throwIfNotFound) throws Exception {
        NodeList nodes = root.getElementsByTagNameNS(namespaceUri, name);
        if (nodes.getLength() > 0)
            return (Element) nodes.item(0);
        else {//from  w w  w .j  a  va2 s .  c o m
            if (throwIfNotFound)
                throw new Exception(
                        String.format(
                                "A node with name '%s' in namespace '%s' was not found.",
                                name, namespaceUri));
            else
                return null;
        }
    }
}

Related

  1. locateElements(Element root, String tagName, String keyAttributeName, String keyAttributeValue)
  2. locateElement(Element root, String tagName, String keyAttributeName, String keyAttributeValue)
  3. valueOfFirstDescendantWithName(Element element, String name)
  4. firstDescendantWithName(Element element, String name)
  5. findNextSiblingElement(Element current)
  6. getListContent(Element listElement, String listItemName, String listItemNamespace)
  7. getStringFromXml(Element validate, Boolean hasHeader)