cmarchand / gaulois-pipe

A XSLT pipelining solution
Mozilla Public License 2.0
9 stars 4 forks source link

Processing a file with a DTD that should be resolved via catalog does not work #39

Open cmarchand opened 6 years ago

cmarchand commented 6 years ago

If I want to use a catalog to resolve DTD declared as PUBLIC DOCTYPE in processeed files, it always fail. Catalog is not used to resolve DTD. Validation of same file, same DTD, same catalog under oXygen is successful.

cmarchand commented 6 years ago

awful.zip This is not restricted to gaulois-pipe, and can be reproduced with xmlresolver and Saxon together ;

Configuration config = Configuration.newConfiguration();
config.setURIResolver(new Resolver(new Catalog("src/test/resources/awfulDtd/awful-catalog.xml")));
Processor proc = new Processor(config);
DocumentBuilder builder = proc.newDocumentBuilder();
builder.build(new File("src/test/resources/awfulDtd/inputFile.xml"));

Produces :

2018-05-17 14:08:38,807 TRACE [main] org.xmlresolver.Catalog     - Default properties: XMLResolver.properties;CatalogManager.properties
2018-05-17 14:08:38,809 DEBUG [main] org.xmlresolver.Catalog     - Loaded xmlresolver.properties from classpath: jar:file:/home/ext-cmarchand/.m2/repository/org/xmlresolver/xmlresolver/0.12.4/xmlresolver-0.12.4.jar!/xmlresolver.properties
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.369 sec <<< FAILURE!
testCatalog(fr.efl.chaine.xslt.CatalogTest)  Time elapsed: 0.32 sec  <<< ERROR!
net.sf.saxon.s9api.SaxonApiException: I/O error reported by XML parser processing file:/home/ext-cmarchand/devel/github/gaulois-pipe/gaulois-pipe/src/test/resources/awfulDtd/inputFile.xml: /fakepath/awful.dtd (Aucun fichier ou dossier de ce type)
etourdot commented 6 years ago

Maybe you should try with class ResolvingXMLReader (according to saxon doc: https://www.saxonica.com/html/documentation/sourcedocs/xml-catalogs.html):

ResolvingXMLReader resolvingXMLReader = new ResolvingXMLReader(new Resolver(new Catalog("src/test/resources/awfulDtd/awful-catalog.xml")));
resolvingXMLReader.parse("src/test/resources/awfulDtd/inputFile.xml");
cmarchand commented 6 years ago

@etourdot : the problem is I use xmlresolver from Norman Walsh, and these classes come from Apache xml-common-resolver (hum, also written by Norman Walsh), and I do not want to add another dependency for resolver. Setting resolver as a EntityResolver on XMLReader should work, but doesn't. @ndw should have a look at it.

etourdot commented 6 years ago

Why adding another dependency ? ResolvingXMLReader is included in xml-common-resolver : https://xerces.apache.org/xml-commons/components/apidocs/resolver/org/apache/xml/resolver/tools/ResolvingXMLReader.html Description is: "This class implements a SAX XMLReader that performs entity resolution using the CatalogResolver." Btw, it's quoted in the § "How to use XML Resolver" in website xmlresolver

cmarchand commented 6 years ago

Because I do not have xml-commons-resolver as dependency in gaulois-pipe.
Because I use another resolver, which is much reliable ; xmlresolver.org

Best,
Christophe

etourdot commented 6 years ago

I misspoke, ResolvingXMLReader is also included in xmlresolver: https://github.com/ndw/xmlresolver/blob/master/src/main/java/org/xmlresolver/tools/ResolvingXMLReader.java

cmarchand commented 6 years ago

Problem is solved by setting an EntityResolver (i.e. an instance of org.xmlresolver.Resolver) in the XMLReader that's used to parse source File.

That solves partially the problem, only for files that go through pipe. But it doesn't solve the problem for files load by fn:document(...) or fn:doc(...). Still some work to do.