Example usage for org.w3c.dom Attr getNamespaceURI

List of usage examples for org.w3c.dom Attr getNamespaceURI

Introduction

In this page you can find the example usage for org.w3c.dom Attr getNamespaceURI.

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:org.osaf.cosmo.xml.DomReader.java

private static Element readElement(Document d, XMLStreamReader reader) throws XMLStreamException {
    Element e = null;/*w  w w.  j a  v a2 s  . c om*/

    String local = reader.getLocalName();
    String ns = reader.getNamespaceURI();
    if (ns != null) {
        String prefix = reader.getPrefix();
        String qualified = prefix != null ? prefix + ":" + local : local;
        e = d.createElementNS(ns, qualified);
    } else {
        e = d.createElement(local);
    }

    //if (log.isDebugEnabled())
    //log.debug("Reading element " + e.getTagName());

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        Attr a = readAttribute(i, d, reader);
        if (a.getNamespaceURI() != null)
            e.setAttributeNodeNS(a);
        else
            e.setAttributeNode(a);
    }

    return e;
}

From source file:org.osaf.cosmo.xml.DomWriter.java

private static void writeAttribute(Attr a, XMLStreamWriter writer) throws XMLStreamException {
    //if (log.isDebugEnabled())
    //log.debug("Writing attribute " + a.getNodeName());

    String local = a.getLocalName();
    if (local == null)
        local = a.getNodeName();// w  ww.j a v a2s .com
    String ns = a.getNamespaceURI();
    String value = a.getValue();

    // was handled by writing the default namespace in writeElement
    if (local.equals("xmlns"))
        return;

    if (ns != null) {
        String prefix = a.getPrefix();
        if (prefix != null)
            writer.writeAttribute(prefix, ns, local, value);
        else
            writer.writeAttribute(ns, local, value);
    } else {
        writer.writeAttribute(local, value);
    }
}

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

private static Element readElement(Document d, XMLStreamReader reader) throws XMLStreamException {
    Element e = null;/*from   w ww.  j  a va 2  s.  c  o  m*/

    String local = reader.getLocalName();
    String ns = reader.getNamespaceURI();
    if (ns != null && !ns.equals("")) {
        String prefix = reader.getPrefix();
        String qualified = prefix != null && !prefix.isEmpty() ? prefix + ":" + local : local;
        e = d.createElementNS(ns, qualified);
    } else {
        e = d.createElement(local);
    }

    //if (log.isDebugEnabled())
    //log.debug("Reading element " + e.getTagName());

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        Attr a = readAttribute(i, d, reader);
        if (a.getNamespaceURI() != null) {
            e.setAttributeNodeNS(a);
        } else {
            e.setAttributeNode(a);
        }
    }

    return e;
}

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

private static void writeAttribute(Attr a, XMLStreamWriter writer) throws XMLStreamException {
    //if (log.isDebugEnabled())
    //log.debug("Writing attribute " + a.getNodeName());

    String local = a.getLocalName();
    if (local == null) {
        local = a.getNodeName();/*  ww w  .j  a  va 2  s . co m*/
    }
    String ns = a.getNamespaceURI();
    String value = a.getValue();

    // was handled by writing the default namespace in writeElement
    if (local.equals("xmlns")) {
        return;
    }

    if (ns != null) {
        String prefix = a.getPrefix();
        if (prefix != null) {
            writer.writeAttribute(prefix, ns, local, value);
        } else {
            writer.writeAttribute(ns, local, value);
        }
    } else {
        writer.writeAttribute(local, value);
    }
}