~ubuntu-branches/ubuntu/precise/xom/precise

« back to all changes in this revision

Viewing changes to src/nu/xom/samples/HelloXMLBase.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2007-11-25 15:50:40 UTC
  • Revision ID: james.westby@ubuntu.com-20071125155040-r75ikcqf1vu0cei7
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 java.io.IOException;
 
25
 
 
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;
 
31
 
 
32
/**
 
33
 * 
 
34
 * <p>
 
35
 *   Demonstrates interaction of actual base URI with 
 
36
 *   <code>xml:base</code> attributes.
 
37
 * </p>
 
38
 * 
 
39
 * @author Elliotte Rusty Harold
 
40
 * @version 1.0
 
41
 *
 
42
 */
 
43
public class HelloXMLBase {
 
44
 
 
45
  public static void main(String[] args) {
 
46
   
 
47
    Document doc;
 
48
    String base1 = "http://www.base1.com";
 
49
    String base2 = "http://www.base2.com";
 
50
    String base3 = "base3.html";
 
51
 
 
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"));
 
59
    
 
60
    Element child2 = new Element("child2");
 
61
    root.appendChild(child2);
 
62
 
 
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));
 
67
 
 
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));
 
72
    
 
73
    try {
 
74
        Serializer serializer 
 
75
          = new Serializer(System.out, "ISO-8859-1");
 
76
        serializer.setPreserveBaseURI(true);
 
77
        serializer.write(doc);
 
78
        serializer.flush();
 
79
        serializer.setPreserveBaseURI(false);
 
80
        serializer.write(doc);
 
81
        serializer.flush();
 
82
    }
 
83
    catch (IOException ex) { 
 
84
        // shouldn't happen on System.out
 
85
        ex.printStackTrace();
 
86
    }
 
87
    
 
88
  }
 
89
 
 
90
}