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

StringformatQName(QName qname)
format Q Name
if (!XMLConstants.DEFAULT_NS_PREFIX.equals(qname.getPrefix())) {
    return qname.getPrefix() + ":" + qname.getLocalPart();
} else {
    return qname.toString();
ClassgetClassForDatatype(QName qname)
get Class For Datatype
return _classMap.get(qname);
StringgetClassName(QName qname)
Returns the className for a given qname e.g., {http://www.w3.org/2001/XMLSchema}decimal → org.w3.2001.XMLSchema.decimal
try {
    StringBuilder className = new StringBuilder();
    StringTokenizer st1 = new StringTokenizer(qname.getNamespaceURI(), "/");
    st1.nextToken(); 
    String domain = st1.nextToken(); 
    StringTokenizer st2 = new StringTokenizer(domain, ".");
    List<String> lDomain = new ArrayList<String>();
    while (st2.hasMoreTokens()) {
...
ListgetDirectChildElementsOnly(QName qName, Element element)
get Direct Child Elements Only
List<Element> elements = new ArrayList<>();
NodeList list = element.getChildNodes();
if (list == null || list.getLength() <= 0) {
    return elements;
for (int i = 0; i < list.getLength(); i++) {
    Node node = list.item(i);
    if (Node.ELEMENT_NODE == node.getNodeType()) {
...
SOAPElementgetFirstChild(SOAPElement body, QName elementName)
get First Child
Iterator updateRequest = body.getChildElements(elementName);
if (!updateRequest.hasNext())
    return null;
return (SOAPElement) updateRequest.next();
StringgetKey(QName name)
get Key
if (name == null) {
    return null;
final StringBuilder sb = new StringBuilder();
final String namespaceURI = name.getNamespaceURI();
if (!namespaceURI.equals(XMLConstants.NULL_NS_URI)) {
    sb.append("{").append(namespaceURI).append("}");
final String prefix = name.getPrefix();
if (!XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
    sb.append(prefix).append(":");
final String localPart = name.getLocalPart();
sb.append(localPart);
return sb.toString();
StringgetLocalAddress(QName port)
get Local Address
return "local://" + new File(System.getProperty("tempdir")).getAbsolutePath().replace('\\', '/') + '?'
        + port.getLocalPart();
TgetMatchingExtensionProvider(Map extensionMap, String namespaceURI, String prefix, String localName)
returns the matching Extension provider for a given QName/namespaceURI+prefix+localName combination
QName subject;
if (localName != null && prefix != null) {
    subject = new QName(namespaceURI, localName, prefix);
} else if (localName != null) {
    subject = new QName(namespaceURI, localName);
} else {
    return null;
Set<QName> qNames = extensionMap.keySet();
for (QName qName : qNames) {
    if (subject.equals(qName)) {
        return extensionMap.get(qName);
return null;
StringgetMediaTypeFromAttributes(Map attributes)
Gets value of mediaType attribute.
for (Entry<QName, String> attribute : attributes.entrySet()) {
    if (attribute.getKey().getLocalPart().equals("mediaType")) {
        return attribute.getValue();
return null;
QNamegetNodeQName(Node el)
get Node Q Name
String localName = el.getLocalName();
String namespaceUri = el.getNamespaceURI();
if (localName == null) {
    String nodeName = el.getNodeName();
    int colonIndex = nodeName.indexOf(":");
    if (colonIndex > 0) {
        localName = nodeName.substring(0, colonIndex);
        namespaceUri = nodeName.substring(colonIndex + 1);
...