Java Utililty Methods XML Namespace

List of utility methods to do XML Namespace

Description

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

Method

StringgetPrefixFromNamespaceDeclaration(String namespace)
Returns any prefix declared with this namespace.
if (!namespace.startsWith(XMLConstants.XMLNS_ATTRIBUTE))
    return null;
int xmlnsLength = XMLConstants.XMLNS_ATTRIBUTE.length();
if (namespace.length() == xmlnsLength) {
    return ""; 
if (namespace.charAt(xmlnsLength) == ':') {
    return namespace.substring(xmlnsLength + 1);
...
javax.xml.namespace.QNamegetRequestMessageType(String intfNamespace, String op, String prefix)
This method returns the request message type QName.
javax.xml.namespace.QName ret = null;
if (prefix != null) {
    ret = new javax.xml.namespace.QName(intfNamespace, op + REQUEST, prefix);
} else {
    ret = new javax.xml.namespace.QName(intfNamespace, op + REQUEST);
return (ret);
StringgetSchemaNamespace(Package pkg)
get Schema Namespace
XmlSchema xmlSchemaAnn = pkg.getAnnotation(XmlSchema.class);
if (xmlSchemaAnn == null) {
    return null;
return xmlSchemaAnn.namespace();
NamespaceContextgetTEINamespaceContext()
Creates a NamespaceContext object with the following list of namespaces:
tei
http://www.tei-c.org/ns/1.0
NamespaceContext ctx = new NamespaceContext() {
    public String getNamespaceURI(String prefix) {
        String uri;
        if (prefix.equals("tei"))
            uri = "http://www.tei-c.org/ns/1.0";
        else
            uri = null;
        return uri;
...
StringgetXmlSchemaNamespace(Class clazz)
Gets the xml schema namespace.
AnnotatedElement pack = clazz.getPackage();
if (pack == null) {
    return "";
XmlSchema schema = pack.getAnnotation(XmlSchema.class);
String namespace = null;
if (schema != null) {
    namespace = schema.namespace();
...
booleanisNamespaceAware()
is Namespace Aware
return getDocumentBuilder().isNamespaceAware();
booleanisValidFragment(final Object obj, final String namespace, final String localPart)
is Valid Fragment
return ((Node) obj).getNamespaceURI().equals(namespace) && ((Node) obj).getLocalName().equals(localPart);
voidlogWriter(Logger logger, String msg, XMLStreamWriter writer, String namespaceURI)
log Writer
if (logger.isDebugEnabled()) {
    logger.debug(writerStatus(msg, writer, namespaceURI));
voidprintNamespace(XMLStreamReader xmlr, int index, StringBuffer result)
print Namespace
String prefix = xmlr.getNamespacePrefix(index);
String uri = xmlr.getNamespaceURI(index);
result.append(" ");
if (prefix == null)
    result.append("xmlns='").append(uri).append("'");
else
    result.append("xmlns:").append(prefix).append("='").append(uri).append("'");
voidprintNamespaces(XMLStreamReader xmlr)
print Namespaces
for (int i = 0; i < xmlr.getNamespaceCount(); i++) {
    printNamespace(xmlr, i);