1 21 22 package nu.xom.samples; 23 24 import java.io.IOException ; 25 26 import nu.xom.Builder; 27 import nu.xom.Document; 28 import nu.xom.Element; 29 import nu.xom.NodeFactory; 30 import nu.xom.ParsingException; 31 import nu.xom.Serializer; 32 33 46 47 public class StreamingXHTMLQualifier extends NodeFactory { 48 49 public final static String XHTML_NAMESPACE 50 = "http://www.w3.org/1999/xhtml"; 51 52 public Element startMakingElement(String name, String namespace) { 53 54 if ("".equals(namespace) || null == namespace) { 55 return super.startMakingElement(name, XHTML_NAMESPACE); 56 } 57 else return super.startMakingElement(name, namespace); 58 } 59 60 public static void main(String [] args) { 61 62 if (args.length <= 0) { 63 System.out.println( 64 "Usage: java nu.xom.samples.StreamingXHTMLQualifier URL" 65 ); 66 return; 67 } 68 69 try { 70 Builder parser = new Builder(new StreamingXHTMLQualifier()); 71 Document doc = parser.build(args[0]); 72 Serializer out = new Serializer(System.out); 73 out.write(doc); 74 } 75 catch (ParsingException ex) { 76 System.out.println(args[0] + " is not well-formed."); 77 System.out.println(ex.getMessage()); 78 } 79 catch (IOException ex) { 80 System.out.println( 81 "Due to an IOException, the parser could not read " 82 + args[0] 83 ); 84 } 85 86 } 87 88 } 89 | Popular Tags |