Afaik, SAX - only a parser. You must select a different library for writing XML.
If you change attributes or change element names and DO NOT change the XML structure, this should be a relatively simple task. Use STaX as an author:
OutputStream out = new FileOutputStream("data.xml");
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(out);
Now add the SAX DefaultHandler:
startDocument(){
writer.writeStartDocument("UTF-8", "1.0");
}
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) {
writer.writeStartElement(namespaceURI, localName);
for(int i=0; i<atts.getLength(); i++){
writer.writeAttribute(atts.getQName(i), atts.getValue(i));
}
}
public void endElement(String uri, localName, qName){
writer.writeEndElement();
}
source
share