Java Utililty Methods XML QName

List of utility methods to do XML QName

Description

The list of methods to do XML QName are organized into topic(s).

Method

QNameconvertToQName(String source, String nameSpaceuri)
Code from Axis1 code base
source = source.trim();
int colon = source.lastIndexOf(":");
String localPart = colon < 0 ? source : source.substring(colon + 1);
String perfix = colon <= 0 ? "" : source.substring(0, colon);
return new QName(nameSpaceuri, localPart, perfix);
QNamecopyQName(QName inName)
copy Q Name
if (inName == null) {
    return null;
return new QName(inName.getNamespaceURI(), inName.getLocalPart());
QNamecrackQName(String qName)
Cracks a combined QName of the form URL:localname
String ns;
String name;
int index = qName.lastIndexOf(':');
if (index >= 0) {
    ns = qName.substring(0, index);
    name = qName.substring(index + 1);
} else {
    ns = "";
...
CollectioncreateCollection(QName... qnames)
create Collection
return Arrays.asList(qnames);
JAXBElementcreateRootElement(T value, QName q_name, Class elementClass)
create Root Element
return new JAXBElement<>(q_name, elementClass, null, value);
Objectextract(final List anyList, final Class classType, final QName eltName)
extract
for (final Object any : anyList) {
    if (any instanceof JAXBElement) {
        final JAXBElement elt = (JAXBElement) any;
        if ((classType != null && classType.equals(elt.getDeclaredType()))
                && (eltName != null && eltName.equals(elt.getName()))) {
            return elt.getValue();
return null;
ListfindAllElements(Element root, QName name, boolean local)
find All Elements
List<Node> list = new ArrayList<Node>();
if (matchNode(root, name, local))
    list.add(root);
for (Node child = root.getFirstChild(); child != null; child = child.getNextSibling()) {
    if (child.getNodeType() != Node.ELEMENT_NODE)
        continue;
    list.addAll(findAllElements((Element) child, name, local));
return list;
ElementfindElement(QName elementName, List content)
find Element
for (Object o : content) {
    if (o instanceof Element) {
        Element u = (Element) o;
        QName n = new QName(u.getNamespaceURI(), u.getLocalName());
        if (n.equals(elementName)) {
            return u;
return null;
ElementfindElementRecursive(Element element, QName elementQName)
find Element Recursive
if (elementQName.equals(getQName(element))) {
    return element;
for (Element subElement : listChildElements(element)) {
    Element foundElement = findElementRecursive(subElement, elementQName);
    if (foundElement != null) {
        return foundElement;
return null;
NodefindNode(Node node, QName name)
Find a Node with a given QName
if (name.getNamespaceURI().equals(node.getNamespaceURI())
        && name.getLocalPart().equals(node.getLocalName()))
    return node;
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    Node ret = findNode(children.item(i), name);
    if (ret != null)
        return ret;
...