1
/* Copyright 2002, 2003 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;
25
import java.io.IOException;
27
import nu.xom.Builder;
28
import nu.xom.Document;
29
import nu.xom.Element;
30
import nu.xom.Elements;
31
import nu.xom.ParsingException;
37
* Demonstrates extracting elements from one document
38
* and inserting them into another document.
41
* @author Elliotte Rusty Harold
45
public class Linkset {
47
public static void main(String[] args) {
49
String url = "http://www.slashdot.org/slashdot.rdf";
52
Builder parser = new Builder();
55
Document document = parser.build(url);
56
Element oldRoot = document.getRootElement();
57
Element newRoot = new Element("linkset");
58
Elements toplevel = oldRoot.getChildElements();
59
for (int i = 0; i < toplevel.size(); i++) {
60
Element element = toplevel.get(i);
61
Element link = element.getFirstChildElement("link",
62
"http://my.netscape.com/rdf/simple/0.9/");
64
newRoot.appendChild(link);
66
System.out.println(newRoot.toXML());
68
catch (ParsingException ex) {
69
System.out.println(url + " is not well-formed.");
71
catch (IOException ex) {
73
"Due to an IOException, the parser could not read " + url