Java XML QName hasChildElement(QName qName, Element element)

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

Description

has Child Element

License

Open Source License

Declaration

public static boolean hasChildElement(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 boolean hasChildElement(QName qName, Element element) {
        List<Element> elements = getChildElements(qName, element);
        return !elements.isEmpty();
    }/*from  w w  w  . j  a va  2s . c  o m*/

    public static List<Element> getChildElements(QName qName, Element element) {
        NodeList list = element.getElementsByTagNameNS(qName.getNamespaceURI(), qName.getLocalPart());
        List<Element> elements = new ArrayList<>();
        if (list == null || list.getLength() <= 0) {
            return elements;
        }
        for (int i = 0; i < list.getLength(); i++) {
            elements.add((Element) list.item(i));
        }
        return elements;
    }
}

Related

  1. getXmlQName(final NamespaceContext context, final String value)
  2. getXmlRootElementQName(Class clazz)
  3. getXMLValue(String xml, String xQuery, QName resultType)
  4. getXSTypeAsString(QName qname)
  5. hasAnnotatedQname(Object obj)
  6. hasGmlNamespace(QName qname)
  7. hasQName(final Node e, final QName name)
  8. hasQName(Node node, QName qname)
  9. isElementName(Element element, QName name)