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

StringgetNoNamespacePath(Stack stack, NamespaceContext ctx)
get No Namespace Path
StringBuilder ret = new StringBuilder();
for (QName q : stack) {
    if (q == null)
        throw new IllegalStateException("q is null");
    ret.append("/");
    ret.append(q.getLocalPart());
return ret.toString();
...
QNamegetNSName(Element e, String qname)
get NS Name
if (qname == null) {
    return null;
int i = qname.indexOf(':');
if (i > 0) {
    String name = qname.substring(i + 1);
    String prefix = qname.substring(0, i);
    return new QName(getNamespaceURI(e, prefix), name);
...
ElementgetOrCreateAsFirstElement(Element parentElement, QName elementQName)
get Or Create As First Element
Element element = getChildElement(parentElement, elementQName);
if (element != null) {
    return element;
Document doc = parentElement.getOwnerDocument();
element = doc.createElementNS(elementQName.getNamespaceURI(), elementQName.getLocalPart());
parentElement.insertBefore(element, getFirstChildElement(parentElement));
return element;
...
QNamegetPartQName(String opName, String suffix, String partName)
part names are not unique across messages.
return new QName(opName + suffix, partName);
ObjectgetPort(Service service, Class seiClass, QName port)
Convenient method to create a sei using service, sei class and port qname.
return service.getPort(port, seiClass);
StringgetPrefix(QName qName)
Returns the prefix of the given QName.
return qNameHasPrefix ? qName.getPrefix() : "";
StringgetQualifiedName(QName qName)
Return the qualified name, that is to say the prefix -if any- with the local name.
if (!XMLConstants.NULL_NS_URI.equals(qName.getNamespaceURI())
        && !XMLConstants.DEFAULT_NS_PREFIX.equals(qName.getPrefix())) {
    return qName.getPrefix() + ":" + qName.getLocalPart();
} else {
    return qName.getLocalPart();
StringgetServiceCode(SOAPMessage soap, QName requestElementQName)
get Service Code
for (SOAPElement eachHeaderElement : getChildElements(soap.getSOAPHeader())) {
    QName headerElementQName = eachHeaderElement.getElementQName();
    if (!"service".equals(headerElementQName.getLocalPart())) {
        continue;
    for (SOAPElement eachServicePart : getChildElements(eachHeaderElement)) {
        QName headerPartQName = eachServicePart.getElementQName();
        if (headerPartQName.getLocalPart().equals("serviceCode")) {
...
StringgetString(QName qName)
Get the full string of qname
if (qName == null)
    throw new NullPointerException("argument is null");
StringBuffer sb = new StringBuffer();
sb.append("NamespaceUri:" + qName.getNamespaceURI() + " ");
sb.append("LocalPart:" + qName.getLocalPart() + " ");
sb.append("Prefix:" + qName.getPrefix());
return sb.toString();
StringgetStringForQName(QName qname, Element e)
Return a string for a particular QName, mapping a new prefix if necessary.
String uri = qname.getNamespaceURI();
String prefix = getPrefix(uri, e);
if (prefix == null) {
    int i = 1;
    prefix = "ns" + i;
    while (getNamespace(prefix, e) != null) {
        i++;
        prefix = "ns" + i;
...