Java Utililty Methods XML Element Namespace

List of utility methods to do XML Element Namespace

Description

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

Method

StringresolveNamespacePrefix(String prefix, Element element)
resolve Namespace Prefix
String namespace = null;
if ("".equals(prefix)) {
    namespace = element.getAttribute("xmlns");
} else {
    namespace = element.getAttribute("xmlns:" + prefix);
if (namespace != null && !"".equals(namespace)) {
    return namespace;
...
voidwriteEndElement(XMLStreamWriter out, String prefix, String namespaceURI)
Write an end element removing the namespace binding if necessary
out.writeEndElement();
if (namespaceURI != null) {
    String resetNamespace = (namespaceURI.length() == 0 ? UNBOUND_NAMESPACE : namespaceURI);
    if (prefix.length() == 0) {
        out.setDefaultNamespace(resetNamespace);
    } else {
        out.setPrefix(prefix, resetNamespace);
voidwriteStartElement(XMLStreamWriter writer, String prefix, String namespaceURI, String nodeName)
If namespaceURI is null, this method calls writer.writeStartElement without namespaceURI argument.
if (namespaceURI != null) {
    if (prefix != null && !NO_PREFIX.equals(prefix)) {
        writer.writeStartElement(prefix, nodeName, namespaceURI);
    } else {
        writer.writeStartElement(namespaceURI, nodeName);
} else {
    writer.writeStartElement(nodeName);
...