1 57 58 59 package sax; 60 61 import org.enhydra.apache.xerces.parsers.SAXParser; 62 import org.xml.sax.SAXException ; 63 import org.xml.sax.ext.DeclHandler ; 64 65 66 67 68 77 public class DTDReader implements DeclHandler { 78 79 89 public void attributeDecl( String eName, String aName,String 90 type, String valueDefault, String value ) throws SAXException { 91 System.out.println( "\nAttributeDecl:" ); 92 System.out.println( " eName = " + eName ); 93 System.out.println( " aName = " + aName ); 94 System.out.println( " type = " + type ); 95 System.out.println( " valueDefault = " + valueDefault ); 96 System.out.println( " value = " + value ); 97 98 } 99 100 107 public void elementDecl( String name, String model ) throws SAXException { 108 System.out.println( "\nElementDecl = " + name ); 109 System.out.println( " ContentModel =" + model +"\n" ); 110 } 111 112 119 public void internalEntityDecl (String name, String value) 120 throws SAXException { 121 System.out.println( "\nInternalEntityDecl" ); 122 System.out.println( " Name = " + name+ ",value = " + value ); 123 124 } 125 126 134 public void externalEntityDecl (String name, String publicId, 135 String systemId) 136 throws SAXException { 137 System.out.println( "\nExternalEntityDecl" ); 138 System.out.println( " Name = " + name + "publicId = " + publicId + "systemId = " + systemId ); 139 } 140 141 142 143 144 149 public static void main( String [] argv ) { 150 151 if ( argv.length != 1 ) { 152 153 System.out.println( "Error: Usage: java -cp ... DTDReader myxmlfile" ); 154 System.exit(0); 155 } 156 157 DTDReader handler = new DTDReader(); 158 159 try { 160 SAXParser parser = new SAXParser( ); 161 parser.setProperty( "http://xml.org/sax/properties/declaration-handler", handler ); 162 System.out.println( "argv = " + argv[0] ); 163 parser.parse( argv[0] ); 164 165 } catch ( Exception ex ){ 166 ex.printStackTrace(); 167 } 168 169 } 170 171 } 172 | Popular Tags |