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 java.io.IOException;
26
import nu.xom.Attribute;
27
import nu.xom.Comment;
28
import nu.xom.Document;
29
import nu.xom.Element;
30
import nu.xom.Serializer;
35
* Demonstrates interaction of actual base URI with
36
* <code>xml:base</code> attributes.
39
* @author Elliotte Rusty Harold
43
public class HelloXMLBase {
45
public static void main(String[] args) {
48
String base1 = "http://www.base1.com";
49
String base2 = "http://www.base2.com";
50
String base3 = "base3.html";
52
Element root = new Element("root");
53
doc = new Document(root);
54
doc.setBaseURI(base1);
55
Element child = new Element("child");
56
root.appendChild(child);
57
child.setBaseURI(base2);
58
child.appendChild(new Comment("here I am"));
60
Element child2 = new Element("child2");
61
root.appendChild(child2);
63
Element child3 = new Element("child3");
64
root.appendChild(child3);
65
child3.addAttribute(new Attribute("xml:base",
66
"http://www.w3.org/XML/1998/namespace", base2));
68
Element child4 = new Element("child4");
69
root.appendChild(child4);
70
child4.addAttribute(new Attribute("xml:base",
71
"http://www.w3.org/XML/1998/namespace", base3));
75
= new Serializer(System.out, "ISO-8859-1");
76
serializer.setPreserveBaseURI(true);
77
serializer.write(doc);
79
serializer.setPreserveBaseURI(false);
80
serializer.write(doc);
83
catch (IOException ex) {
84
// shouldn't happen on System.out