java - Handle private external DTD with dependencies in SAX parser -


i'm trying parse xml file private external dtd specified in doctype this:

<!doctype my1 system "my1.dtd"> 

to hanlde dtd locally validation specifed entityresolver xmlreader parser:

        //use local dtd         parser.setentityresolver(new entityresolver() {             @override             public inputsource resolveentity(string publicid, string systemid) throws saxexception, ioexception {                 if (systemid.contains(my1dtd)) {                     return new inputsource(myclass.class.getresourceasstream(my1_dtd_resource_path));                 } else {                     return null;                 }             }         }); 

this inputsource returned correctly, there problem related dtd: inside dtd there references dtds. put dtds in same package. when application deployed on tomcat filenotfoundexception d:\apache-tomcat-6.0.29\bin\my2.dtd (the system cannot find file specified) thrown.

my question is: how can specify dependency correctly? should constructed in resolveentity method or made mistake in path (my2.dtd declared <!entity % my2 system "my2.dtd"> inside my1.dtd , stored in same package).

the resolveentity should invoked when parser needs load my2.dtd file.

thus ou need modify in similar way:

 public inputsource resolveentity(string publicid, string systemid) throws saxexception, ioexception {             if (systemid.contains(my1dtd)) {                 return new inputsource(myclass.class.getresourceasstream(my1_dtd_resource_path));             } else if (systemid.contains(my2dtd)) {                 return new inputsource(myclass.class.getresourceasstream(my2_dtd_resource_path));             } else {                 return null;             }         } 

however, avoid such work should consider using resolver, the apache resolver. resolver relies on oasis entity resolution / xml catalogs, allows create catalog in xml format, read resolver won't need modify code each time have new dtd or move place or whatever. (this resolver package comes bundled apache xerces distribution, if parser using).


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -