1 38 39 40 package com.sun.xml.fastinfoset.tools; 41 42 import com.sun.xml.fastinfoset.stax.StAXDocumentSerializer; 43 import java.io.IOException ; 44 import java.io.InputStream ; 45 import java.io.OutputStream ; 46 import javax.xml.parsers.ParserConfigurationException ; 47 import javax.xml.parsers.SAXParser ; 48 import javax.xml.parsers.SAXParserFactory ; 49 import org.xml.sax.SAXException ; 50 import com.sun.xml.fastinfoset.stax.SAX2StAXWriter; 51 52 public class XML_SAX_StAX_FI extends TransformInputOutput { 53 54 public XML_SAX_StAX_FI() { 55 } 56 57 public void parse(InputStream xml, OutputStream finf) throws Exception { 58 StAXDocumentSerializer documentSerializer = new StAXDocumentSerializer(); 59 documentSerializer.setOutputStream(finf); 60 61 SAX2StAXWriter saxTostax = new SAX2StAXWriter(documentSerializer); 62 63 SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); 64 saxParserFactory.setNamespaceAware(true); 65 SAXParser saxParser = saxParserFactory.newSAXParser(); 66 67 saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", saxTostax); 68 saxParser.parse(xml, saxTostax); 69 xml.close(); 70 finf.close(); 71 } 72 73 public static void main(String [] args) throws Exception { 74 XML_SAX_StAX_FI s = new XML_SAX_StAX_FI(); 75 s.parse(args); 76 } 77 78 } 79 | Popular Tags |