1 38 39 package samples.stax; 40 41 import java.io.File ; 42 import java.io.InputStream ; 43 import java.io.FileInputStream ; 44 import java.io.FileOutputStream ; 45 import java.io.BufferedInputStream ; 46 import java.io.BufferedOutputStream ; 47 import java.io.FileNotFoundException ; 48 49 import javax.xml.stream.XMLStreamWriter; 50 import javax.xml.stream.XMLOutputFactory; 51 import javax.xml.stream.XMLStreamException; 52 53 import com.sun.xml.fastinfoset.QualifiedName; 54 import com.sun.xml.fastinfoset.sax.AttributesHolder; 55 import com.sun.xml.fastinfoset.stax.StAXDocumentSerializer; 56 57 70 71 public class FastInfosetSerializer { 72 73 74 public FastInfosetSerializer() { 75 } 76 77 public static void main(String [] args) { 78 if (args.length != 1) { 79 displayUsageAndExit(); 80 } 81 82 try { 83 File output = new File (args[0]); 84 BufferedOutputStream fos = new BufferedOutputStream (new FileOutputStream (output)); 85 86 StAXDocumentSerializer s = new StAXDocumentSerializer(); 88 s.setOutputStream(fos); 89 90 AttributesHolder attributes = new AttributesHolder(); 91 attributes.clear(); 92 93 String temp = null; 94 95 s.writeStartDocument(); 97 98 String namespaceURI = "http://www.sun.com/schema/spidermarkexpress/sm-inv"; 100 String prefix = "ns1"; 101 String localPart = "invoice"; 102 103 105 s.writeStartElement(prefix, localPart, namespaceURI); 106 s.writeNamespace(prefix, namespaceURI); 107 s.setPrefix(prefix, namespaceURI); 108 109 s.writeCharacters("\n\t"); 111 s.writeStartElement("header"); 112 113 s.writeCharacters("\n\t\t"); 115 s.writeStartElement("IssueDateTime"); 116 s.writeCharacters("2003-03-13T13:13:32-08:00"); 117 s.writeEndElement(); 118 119 s.writeCharacters("\n\t\t"); 121 s.writeStartElement("Identifier"); 122 s.writeAttribute("schemeAgencyName", "ISO"); 123 s.writeAttribute("schemeName", "Invoice"); 124 s.writeCharacters("15570720"); 125 s.writeEndElement(); 126 127 s.writeCharacters("\n\t\t"); 129 s.writeStartElement("POIdentifier"); 130 s.writeAttribute("schemeName", "Generic"); 131 s.writeAttribute("schemeAgencyName", "ISO"); 132 s.writeCharacters("691"); 133 s.writeEndElement(); 134 135 s.writeCharacters("\n\t"); 137 s.writeEndElement(); 138 139 s.writeCharacters("\n"); 141 s.writeEndElement(); 142 143 s.writeEndDocument(); 144 } catch (Exception e) { 145 e.printStackTrace(); 146 } 147 } 148 149 private static void displayUsageAndExit() { 150 System.err.println("Usage: ant FIStAXSerializer or samples.stax.FastInfosetSerializer FI_output_file"); 151 System.exit(1); 152 } 153 } 154 | Popular Tags |