Java XML QName getDirectChildElementsOnly(QName qName, Element element)

Here you can find the source of getDirectChildElementsOnly(QName qName, Element element)

Description

get Direct Child Elements Only

License

Open Source License

Declaration

public static List<Element> getDirectChildElementsOnly(QName qName, Element element) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.*;
import javax.xml.namespace.QName;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<Element> getDirectChildElementsOnly(QName qName, Element element) {
        List<Element> elements = new ArrayList<>();
        NodeList list = element.getChildNodes();
        if (list == null || list.getLength() <= 0) {
            return elements;
        }/*w  w  w  .  ja va  2 s . com*/
        for (int i = 0; i < list.getLength(); i++) {
            Node node = list.item(i);
            if (Node.ELEMENT_NODE == node.getNodeType()) {
                Element elem = (Element) node;
                if (qName == null) {
                    elements.add(elem);
                } else if (qName.getNamespaceURI().equals(elem.getNamespaceURI())) {
                    if (qName.getLocalPart().equals("*") || qName.getLocalPart().equals(elem.getLocalName())) {
                        elements.add(elem);
                    }
                }
            }
        }
        return elements;
    }
}

Related

  1. findElementRecursive(Element element, QName elementQName)
  2. findNode(Node node, QName name)
  3. formatQName(QName qname)
  4. getClassForDatatype(QName qname)
  5. getClassName(QName qname)
  6. getFirstChild(SOAPElement body, QName elementName)
  7. getKey(QName name)
  8. getLocalAddress(QName port)
  9. getMatchingExtensionProvider(Map extensionMap, String namespaceURI, String prefix, String localName)