1 21 22 package nu.xom.samples; 23 24 import java.io.IOException ; 25 26 import nu.xom.Attribute; 27 import nu.xom.Builder; 28 import nu.xom.Element; 29 import nu.xom.NodeFactory; 30 import nu.xom.Nodes; 31 import nu.xom.ParsingException; 32 33 46 public class StreamingCommentReader extends NodeFactory { 47 48 private Nodes empty = new Nodes(); 49 50 public Nodes makeComment(String data) { 52 System.out.println(data); 53 return empty; 54 } 55 56 public Nodes makeText(String data) { 58 return empty; 59 } 60 61 public Element makeRootElement(String name, String namespace) { 62 return new Element(name, namespace); 63 } 64 65 public Element startMakingElement(String name, String namespace) { 66 return null; 67 } 68 69 public Nodes makeAttribute(String name, String URI, 70 String value, Attribute.Type type) { 71 return empty; 72 } 73 74 public Nodes makeDocType(String rootElementName, 75 String publicID, String systemID) { 76 return empty; 77 } 78 79 public Nodes makeProcessingInstruction( 80 String target, String data) { 81 return empty; 82 } 83 84 public static void main(String [] args) { 85 86 if (args.length <= 0) { 87 System.out.println("Usage: java nu.xom.samples.CommentReader URL"); 88 return; 89 } 90 91 try { 92 Builder parser = new Builder(new StreamingCommentReader()); 93 parser.build(args[0]); 94 } 95 catch (ParsingException ex) { 96 System.out.println(args[0] + " is not well-formed."); 97 System.out.println(ex.getMessage()); 98 } 99 catch (IOException ex) { 100 System.out.println( 101 "Due to an IOException, the parser could not read " 102 + args[0] 103 ); 104 } 105 106 } 107 108 } | Popular Tags |