public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { characters(ch,start,length); }
/** * Create a new {@link javax.xml.transform.Result} that produces * a result on the specified {@link javax.xml.stream.XMLStreamWriter} * * @param writer the XMLStreamWriter * @throws IllegalArgumentException iff the writer is null */ public StAXResult(XMLStreamWriter writer) { if( writer == null ) { throw new IllegalArgumentException(); } super.setHandler(new ContentHandlerToXMLStreamWriter( writer )); }
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); } }
/** * 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)); } } }
marshaller = new Marshaller(new SafeContentHandler(new ContentHandlerToXMLStreamWriter( sWriter))); marshaller.setRootElement(part.getName().getLocalPart());