/** * Generate a StAX writeAttribute event for each attribute * * @param atts * attributes from the SAX event */ private void writeAttributes(Attributes atts) throws XMLStreamException { for (int i = 0; i < atts.getLength(); i++) { final String prefix = getPrefix(atts.getQName(i)); if(!prefix.equals("xmlns")) { // defend againts broken transformers that report xmlns decls as attrs staxWriter.writeAttribute( prefix, atts.getURI(i), atts.getLocalName(i), atts.getValue(i)); } } }
public void startElement( String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { try { staxWriter.writeStartElement( getPrefix(qName), localName, namespaceURI); String uri, prefix; while (prefixBindings.size() != 0) { uri = (String)prefixBindings.pop(); prefix = (String)prefixBindings.pop(); if (prefix.length() == 0) { staxWriter.setDefaultNamespace(uri); } else { staxWriter.setPrefix(prefix, uri); } // this method handles "", null, and "xmlns" prefixes properly staxWriter.writeNamespace(prefix, uri); } writeAttributes(atts); } catch (XMLStreamException e) { throw new SAXException(e); } }