KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nu > xom > samples > PrettyFibonacci


1 /* Copyright 2002, 2003 Elliotte Rusty Harold
2    
3    This library is free software; you can redistribute it and/or modify
4    it under the terms of version 2.1 of the GNU Lesser General Public
5    License as published by the Free Software Foundation.
6    
7    This library is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10    GNU Lesser General Public License for more details.
11    
12    You should have received a copy of the GNU Lesser General Public
13    License along with this library; if not, write to the
14    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15    Boston, MA 02111-1307 USA
16    
17    You can contact Elliotte Rusty Harold by sending e-mail to
18    elharo@metalab.unc.edu. Please include the word "XOM" in the
19    subject line. The XOM home page is located at http://www.xom.nu/
20 */

21
22 package nu.xom.samples;
23
24 import java.io.IOException JavaDoc;
25 import java.math.BigInteger JavaDoc;
26
27 import nu.xom.Document;
28 import nu.xom.Element;
29 import nu.xom.Serializer;
30
31 /**
32  * <p>
33  * Demonstrates using a <code>Serializer</code> object
34  * to insert indents and line breaks in XML.
35  * </p>
36  *
37  * @author Elliotte Rusty Harold
38  * @version 1.0
39  *
40  */

41 public class PrettyFibonacci {
42
43     public static void main(String JavaDoc[] args) {
44    
45         BigInteger JavaDoc low = BigInteger.ONE;
46         BigInteger JavaDoc high = BigInteger.ONE;
47
48 /* <mathml:math xmlns:mathml="http://www.w3.org/1998/Math/MathML">
49   <mathml:mrow>
50     <mathml:mi>f(1)</mathml:mi>
51     <mathml:mo>=</mathml:mo>
52     <mathml:mn>1</mathml:mn>
53   </mathml:mrow> */

54       String JavaDoc 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 JavaDoc 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 JavaDoc ex) {
82         System.err.println(ex);
83       }
84     }
85
86 }
Popular Tags