1 21 22 package nu.xom.samples; 23 24 import java.io.BufferedOutputStream ; 25 import java.io.FileOutputStream ; 26 import java.io.IOException ; 27 import java.io.OutputStream ; 28 import java.math.BigInteger ; 29 30 import nu.xom.Document; 31 import nu.xom.Element; 32 import nu.xom.Serializer; 33 34 44 public class FibonacciFile { 45 46 public static void main(String [] args) { 47 48 BigInteger low = BigInteger.ONE; 49 BigInteger high = BigInteger.ONE; 50 51 Element root = new Element("Fibonacci_Numbers"); 52 for (int i = 1; i <= 10; i++) { 53 Element fibonacci = new Element("fibonacci"); 54 fibonacci.appendChild(low.toString()); 55 root.appendChild(fibonacci); 56 57 BigInteger temp = high; 58 high = high.add(low); 59 low = temp; 60 } 61 Document doc = new Document(root); 62 try { 63 OutputStream out = new FileOutputStream ("fibonacci.xml"); 64 out = new BufferedOutputStream (out); 65 Serializer serializer 66 = new Serializer(out, "ISO-8859-1"); 67 serializer.write(doc); 68 } 69 catch (IOException ex) { 70 System.err.println("This shouldn't happen for Latin-1!"); 71 } 72 73 } 74 75 } | Popular Tags |