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