Java Utililty Methods XML Child Get by Namespace

List of utility methods to do XML Child Get by Namespace

Description

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

Method

ListgetChildElementsByTagNameNS(Element parent, String namespaceURI, String localName)
get Child Elements By Tag Name NS
List<Element> elems = new ArrayList<Element>();
NodeList nodes = parent.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
    Node node = nodes.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE && node.getNamespaceURI().equals(namespaceURI)
            && node.getLocalName().equals(localName)) {
        elems.add((Element) node);
return elems;
Element[]getChildElementsByTagNameNS(Element parentElement, String namespaceURI, String localName)
Retrieves all immediate child elements of the specified element whose names match the provided name parameter.
List children = new ArrayList();
NodeList nodes = parentElement.getChildNodes();
int length = nodes.getLength();
for (int index = 0; index < length; ++index) {
    if (nodes.item(index).getNodeType() == Node.ELEMENT_NODE
            && namespaceURI.equals(nodes.item(index).getNamespaceURI())
            && localName.equals(nodes.item(index).getNodeName())) {
        children.add(nodes.item(index));
...
voidgetChildElementsByTagNameNS(Vector vector, Node node, String tagName, String namespace)
get Child Elements By Tag Name NS
NodeList list = node.getChildNodes();
for (int i = 0; list != null && i < list.getLength(); i++) {
    try {
        Element element = (Element) list.item(i);
        if (tagName.equals(getElementLocalName(element))
                && namespace.equals(getElementNamespaceURI(element))) {
            vector.addElement(element);
        } else {
...
StringgetChildElementValueNS(Element parentElm, String elementNamespaceURI, String elementLocalName)
get Child Element Value NS
String elementValue = null;
NodeList elemList = parentElm.getElementsByTagNameNS(elementNamespaceURI, elementLocalName);
if (elemList != null && elemList.getLength() > 0) {
    Element elm = (Element) elemList.item(0);
    NodeList childNodes = elm.getChildNodes();
    StringBuffer value = new StringBuffer();
    for (int elemCount = 0; elemCount < childNodes.getLength(); elemCount++) {
        if (childNodes.item(elemCount) instanceof org.w3c.dom.Text) {
...