1 21 22 package nu.xom.samples; 23 24 25 import java.io.IOException ; 26 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; 32 33 34 45 public class Linkset { 46 47 public static void main(String [] args) { 48 49 String url = "http://www.slashdot.org/slashdot.rdf"; 50 51 try { 52 Builder parser = new Builder(); 53 54 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/"); 63 link.detach(); 64 newRoot.appendChild(link); 65 } 66 System.out.println(newRoot.toXML()); 67 } 68 catch (ParsingException ex) { 69 System.out.println(url + " is not well-formed."); 70 } 71 catch (IOException ex) { 72 System.out.println( 73 "Due to an IOException, the parser could not read " + url 74 ); 75 } 76 77 } 79 } 80 81 | Popular Tags |