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

QNamegetThreddsCatalogAttributeQName(String localName)
get Thredds Catalog Attribute Q Name
return new QName(XMLConstants.NULL_NS_URI, localName);
ClassgetTypeFromQName(final QName name)
Return a primitive Class from the specified XML QName (extracted from an xsd file).
if (name != null) {
    final Class result = CLASS_BINDING.get(name.getLocalPart());
    if (result == null) {
        throw new IllegalArgumentException("unexpected type:" + name);
    return result;
return null;
...
QNamegetTypeQName(Class type)
get Type Q Name
String namespace = getSchemaNamespace(type.getPackage());
String localPart = getTypeLocalName(type);
if (localPart == null) {
    return null;
return new QName(namespace, localPart);
StringgetUniquePOAName(QName serviceName, String portName, String poaName)
get Unique POA Name
String result = "{" + serviceName.getNamespaceURI() + "}" + serviceName.getLocalPart() + "#" + portName;
if (poaName != null) {
    result += "#" + poaName;
return result;
QNamegetValueAsQName(XMLStreamReader reader, String value)
Returns a QName from a string.
if (value != null) {
    int index = value.indexOf(':');
    String prefix = index == -1 ? "" : value.substring(0, index);
    String localName = index == -1 ? value : value.substring(index + 1);
    String ns = reader.getNamespaceContext().getNamespaceURI(prefix);
    if (ns == null) {
        ns = "";
    return new QName(ns, localName, prefix);
} else {
    return null;
QNamegetXmlElementRefOrElementQName(Class jaxbClass, Field field)
Get the name of the field by looking at the XmlElement annotation.
XmlElementRef xmlElementRef = (XmlElementRef) getAnnotation(field, XmlElementRef.class);
if (xmlElementRef != null) {
    return new QName(xmlElementRef.namespace(), xmlElementRef.name());
XmlElement xmlElement = (XmlElement) getAnnotation(field, XmlElement.class);
if (xmlElement == null || xmlElement.name().equals("##default")) {
    return new QName("", field.getName());
return new QName(xmlElement.namespace(), xmlElement.name());
QNamegetXmlQName(final NamespaceContext context, final String value)
get Xml Q Name
if (value == null) {
    return null;
} else {
    final int colonIndex = value.indexOf(':');
    if (colonIndex == -1) {
        return new QName(value);
    } else {
        final String prefix = value.substring(0, colonIndex);
...
QNamegetXmlRootElementQName(Class clazz)
get Xml Root Element Q Name
XmlRootElement root = (XmlRootElement) getAnnotation(clazz, XmlRootElement.class);
if (root == null) {
    return null;
String name = root.name();
String namespace = root.namespace();
if (name == null || name.length() == 0 || name.equals("##default")) {
    name = getSimpleName(clazz.getCanonicalName());
...
ObjectgetXMLValue(String xml, String xQuery, QName resultType)
get XML Value
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(xml)));
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xPath = xPathfactory.newXPath();
XPathExpression xPathExpression = xPath.compile(xQuery);
return xPathExpression.evaluate(doc, resultType);
StringgetXSTypeAsString(QName qname)
Return XS type of the qualified name or XS String type in case of null.
if (qname == null) {
    return XS_NAMESPACE_URI + "#string";
} else {
    String namaspace = qname.getNamespaceURI() != null ? qname.getNamespaceURI() : XS_NAMESPACE_URI;
    return namaspace + "#" + qname.getLocalPart();