Example usage for javax.xml.stream XMLStreamWriter setDefaultNamespace

List of usage examples for javax.xml.stream XMLStreamWriter setDefaultNamespace

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter setDefaultNamespace.

Prototype

public void setDefaultNamespace(String uri) throws XMLStreamException;

Source Link

Document

Binds a URI to the default namespace This URI is bound in the scope of the current START_ELEMENT / END_ELEMENT pair.

Usage

From source file:org.unitedinternet.cosmo.util.DomWriter.java

private static void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException {
    //if (log.isDebugEnabled())
    //log.debug("Writing element " + e.getNodeName());

    String local = e.getLocalName();
    if (local == null) {
        local = e.getNodeName();//from   w ww.  j a v a  2s.  co m
    }

    String ns = e.getNamespaceURI();
    if (ns != null) {
        String prefix = e.getPrefix();
        if (prefix != null) {
            writer.writeStartElement(prefix, local, ns);
            writer.writeNamespace(prefix, ns);
        } else {
            writer.setDefaultNamespace(ns);
            writer.writeStartElement(ns, local);
            writer.writeDefaultNamespace(ns);
        }
    } else {
        writer.writeStartElement(local);
    }

    NamedNodeMap attributes = e.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        writeAttribute((Attr) attributes.item(i), writer);
    }

    NodeList children = e.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        writeNode(children.item(i), writer);
    }

    writer.writeEndElement();
}