1
/* Copyright 2002-2004 Elliotte Rusty Harold
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.
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.
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
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/
22
package nu.xom.samples;
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;
30
import nu.xom.XMLException;
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.
40
* @author Elliotte Rusty Harold
44
public class SimpleSVG {
46
public static void main(String[] args) {
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"
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);
71
// Serialize the document onto System.out
72
System.out.println(doc.toXML());
75
catch (XMLException ex) {
76
System.err.println(ex);