Example usage for org.w3c.dom Attr getPrefix

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

Introduction

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

Prototype

public String getPrefix();

Source Link

Document

The namespace prefix of this node, or null if it is unspecified.

Usage

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();//from  w w w .  j  av a  2  s. c  o  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);
    }
}

From source file:org.regenstrief.util.XMLUtil.java

/**
 * Strips namespaces and prefixes from a Node tree
 * /*from  w  w  w .java  2  s.c  o m*/
 * @param n the root Node
 * @return the stripped Node
 **/
public final static Node stripNamespaces(final Node n) {
    if (n == null) {
        return null;
    }

    final Document doc = n.getOwnerDocument();
    if (n instanceof Element) {
        final Element eOld = (Element) n;
        final Element eNew = doc.createElement(getLocalName(eOld));
        final NamedNodeMap map = eOld.getAttributes();
        for (int i = 0, size = size(map); i < size; i++) {
            final Attr attr = (Attr) map.item(i);
            String name = attr.getName();
            if (name == null) {
                name = attr.getLocalName();
            }
            if (!("xmlns".equals(name) || ((name != null) && name.startsWith("xmlns:"))
                    || "xmlns".equals(attr.getPrefix()))) {
                final int j = name.indexOf(':');
                eNew.setAttribute(j < 0 ? name : name.substring(j + 1), attr.getValue());
            }
        }
        final NodeList list = n.getChildNodes();
        for (int i = 0, size = size(list); i < size; i++) {
            appendChild(eNew, stripNamespaces(list.item(i)));
        }
        return eNew;
    } else if (n instanceof Attr) {
        return null;
    }
    return n.cloneNode(false);
}

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();/* w w  w . j a  va 2  s .c  o  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);
    }
}