Java XML QName Create toQName(NamespaceContext namespaceContext, String qualifiedName)

Here you can find the source of toQName(NamespaceContext namespaceContext, String qualifiedName)

Description

Return the qname represented by the qualified name.

License

Apache License

Parameter

Parameter Description
namespaceContext The namespace context.
qualifiedName The qualified name.

Return

The qname.

Declaration

public static QName toQName(NamespaceContext namespaceContext, String qualifiedName) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;

public class Main {
    /**//w w  w. j ava2 s.c o  m
     * Return the qname represented by the qualified name.
     * @param namespaceContext The namespace context.
     * @param qualifiedName The qualified name.
     * @return The qname.
     */
    public static QName toQName(NamespaceContext namespaceContext, String qualifiedName) {
        final int index = qualifiedName.indexOf(':');
        if (index == -1) {
            return new QName(qualifiedName);
        } else {
            String prefix = qualifiedName.substring(0, index);
            String localName = qualifiedName.substring(index + 1);
            String namespaceURI = getNormalisedValue(namespaceContext.getNamespaceURI(prefix));
            return new QName(namespaceURI, localName, prefix);
        }
    }

    /**
     * Get the normalised value of the string.
     * @param value The string value.
     * @return The normalised value.
     */
    public static String getNormalisedValue(final String value) {
        if (value != null)
            return value;
        return "";
    }
}

Related

  1. createQNameWithCustomNamespace(String key)
  2. getEmptyQName()
  3. string2qname(String name)
  4. stringToQName(String s)
  5. toQName(Map setProps)
  6. toQName(String namespaceUri, String qualifiedName)
  7. toQName(String s)
  8. toQNameArray(String[] array)