KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Copyright 2002-2004 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 nu.xom.Comment;
25 import nu.xom.DocType;
26 import nu.xom.Document;
27 import nu.xom.Element;
28 import nu.xom.ProcessingInstruction;
29 import nu.xom.Text;
30 import nu.xom.XMLException;
31
32 /**
33  *
34  * <p>
35  * Demonstrates the creation and serialization of an SVG document
36  * that uses namespaces and the default namespace
37  * and includes a document type declaration.
38  * </p>
39  *
40  * @author Elliotte Rusty Harold
41  * @version 1.0
42  *
43  */

44 public class SimpleSVG {
45
46   public static void main(String JavaDoc[] args) {
47      
48     try {
49       // Create the document
50
DocType svgDOCTYPE = new DocType(
51        "svg", "-//W3C//DTD SVG 1.0//EN",
52        "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"
53       );
54        
55       // Fill the document
56
Element root = new Element("svg",
57         "http://www.w3.org/2000/svg");
58       Document doc = new Document(root);
59       doc.insertChild(svgDOCTYPE, 0);
60       ProcessingInstruction xmlstylesheet = new ProcessingInstruction("xml-stylesheet",
61        "type=\"text/css\" HREF=\"standard.css\"");
62       doc.insertChild(xmlstylesheet, 0);
63       Comment comment = new Comment(
64        "An example from Chapter 10 of Processing XML with Java");
65       doc.insertChild(comment, doc.indexOf(root));
66       Element desc = new Element("desc", "http://www.w3.org/2000/svg");
67       root.appendChild(desc);
68       Text descText = new Text("An example from Processing XML with Java");
69       desc.appendChild(descText);
70       
71       // Serialize the document onto System.out
72
System.out.println(doc.toXML());
73         
74     }
75     catch (XMLException ex) {
76       System.err.println(ex);
77     }
78   
79   }
80
81 }
82
83
Popular Tags