beckchr / staxon

JSON via StAX
107 stars 47 forks source link

xsi:schemaLocation attribute mapped even when JsonXMLOutputFactory.PROP_NAMESPACE_DECLARATIONS set to false #14

Closed genjosanzo closed 11 years ago

genjosanzo commented 11 years ago

I've been trying to find a way to avoid propagating the xml nameSpaces while mapping my xml to a json, and setting the property JsonXMLOutputFactory.PROP_NAMESPACE_DECLARATIONS to false seems the right path. In fact that way the Namespaces won't get propagated.

However their schemaLocations will be added to the resulting Json and that is something I'd like to avoid (since they make sense only together with the namespaces)

beckchr commented 11 years ago

Maybe you are right and this should be filtered by StAXON. For now, you should wrap your writer and suppress the attribute like this:

    writer = new StreamWriterDelegate(writer) {
        @Override
        public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
            if (!XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(namespaceURI)) {
                super.writeAttribute(namespaceURI, localName, value);
            }
        }
        @Override
        public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
            if (!XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(namespaceURI)) {
                super.writeAttribute(prefix, namespaceURI, localName, value);
            }
        }
    };