1 21 22 package nu.xom.samples; 23 24 import java.math.BigInteger ; 25 26 import nu.xom.Attribute; 27 import nu.xom.DocType; 28 import nu.xom.Document; 29 import nu.xom.Element; 30 31 42 public class ValidFibonacci { 43 44 public static void main(String [] args) { 45 46 BigInteger low = BigInteger.ONE; 47 BigInteger high = BigInteger.ONE; 48 49 Element root = new Element("Fibonacci_Numbers"); 50 for (int i = 1; i <= 10; i++) { 51 Element fibonacci = new Element("fibonacci"); 52 fibonacci.appendChild(low.toString()); 53 Attribute index = new Attribute("index", String.valueOf(i)); 54 fibonacci.addAttribute(index); 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 DocType doctype 63 = new DocType("Fibonacci_Numbers", "fibonacci.dtd"); 64 doc.insertChild(doctype, 0); 65 System.out.println(doc.toXML()); 66 67 } 68 69 } | Popular Tags |