1 21 22 package nu.xom.samples; 23 24 import java.io.IOException ; 25 import java.math.BigInteger ; 26 27 import nu.xom.Document; 28 import nu.xom.Element; 29 import nu.xom.Serializer; 30 31 41 public class PrettyFibonacci { 42 43 public static void main(String [] args) { 44 45 BigInteger low = BigInteger.ONE; 46 BigInteger high = BigInteger.ONE; 47 48 54 String namespace = "http://www.w3.org/1998/Math/MathML"; 55 Element root = new Element("mathml:math", namespace); 56 for (int i = 1; i <= 10; i++) { 57 Element mrow = new Element("mathml:mrow", namespace); 58 Element mi = new Element("mathml:mi", namespace); 59 Element mo = new Element("mathml:mo", namespace); 60 Element mn = new Element("mathml:mn", namespace); 61 mrow.appendChild(mi); 62 mrow.appendChild(mo); 63 mrow.appendChild(mn); 64 root.appendChild(mrow); 65 mi.appendChild("f(" + i + ")"); 66 mo.appendChild("="); 67 mn.appendChild(low.toString()); 68 69 BigInteger temp = high; 70 high = high.add(low); 71 low = temp; 72 } 73 Document doc = new Document(root); 74 75 Serializer serializer = new Serializer(System.out); 76 serializer.setIndent(4); 77 serializer.setMaxLength(64); 78 try { 79 serializer.write(doc); 80 } 81 catch (IOException ex) { 82 System.err.println(ex); 83 } 84 } 85 86 } | Popular Tags |