1 21 22 package nu.xom.samples; 23 24 25 import java.io.FileOutputStream ; 26 import java.io.IOException ; 27 import java.io.OutputStream ; 28 29 import nu.xom.Attribute; 30 import nu.xom.Document; 31 import nu.xom.Element; 32 import nu.xom.Serializer; 33 34 39 public class EncodingDemo { 40 41 public static void main(String [] args) { 42 43 String encoding = "ISO-8859-2"; 44 if (args.length > 0) encoding = args[0]; 45 Element root = new Element("root"); 46 Document doc = new Document(root); 47 48 for (int i = 0xA0; i <= 0x1FF; i++) { 49 Element data = new Element("data"); 50 data.appendChild((char) i + ""); 51 data.addAttribute( 52 new Attribute("character", String.valueOf(i)) 53 ); 54 root.appendChild(data); 55 } 56 57 try { 58 OutputStream out 59 = new FileOutputStream ("data_" + encoding + ".xml"); 60 Serializer serializer = new Serializer(out, encoding); 61 serializer.setIndent(4); 62 serializer.write(doc); 63 serializer.flush(); 64 out.close(); 65 } 66 catch (IOException ex) { 67 ex.printStackTrace(); 68 } 69 70 71 } 72 73 } 74 | Popular Tags |