Support #2192
closedCannot get DTD validation to work with com.saxonica.Validate and CatalogResolver
0%
Description
Hi,
Hopefully I am just overlooking something simple, but I have not been able to get Saxon to validate an instance XML against a DTD. I have broken down the problem into a simple example. We are using the Apache Catalog Resolver, which is working perfectly fine with Saxon transforms and schema-based validation of instance XMLs, but I cannot get it to work with a DTD.
In my attached test case the files are as follows:
doSaxonValidate: shell script to run a validation using com.saxonica.Validate
CatalogManager.properties: Apache Catalog Manager Properties file for specifying catalog location
catalog.xml: my bare bones catalog to locate the dtd
instance.xml: my simple example instance XML file
xml-resolver.jar: Apache XML resolver jar (version 1.2)
dtd/simple.dtd: my simple dtd used to validate the instance XML
To run the test:
-
Expand the attached tar.gz into a directory
-
Edit the doSaxonValidate script. Modify the SAXON_JAR variable to contain the location to your Saxon-EE jar and license. We put our Saxon license in a jar file, and add the jar to the classpath, your situation may vary.
-
Run: ./doSaxonValidate instance.xml -t
This is the output that I get:
[pubsdm1:@pubsjsdev1:/home/pubsdm1/jrm29/saxonValidate
$ doSaxonValidate instance.xml -t
Parse catalog: file:/home/pubsdm1/jrm29/saxonValidate/catalog.xml
Loading catalog: file:/home/pubsdm1/jrm29/saxonValidate/catalog.xml
Default BASE: file:/home/pubsdm1/jrm29/saxonValidate/catalog.xml
override: yes
OVERRIDE: yes
public: -//MYORG//DTD SIMPLE DTD//EN
dtd/simple.dtd
PUBLIC: -//MYORG//DTD SIMPLE DTD//EN
file:/home/pubsdm1/jrm29/saxonValidate/dtd/simple.dtd
Saxon-EE 9.5.1.7J from Saxonica
Java version 1.6.0_27-rev
Using license serial number V002327
Schema checking successful. Time: 20 milliseconds
Using parser org.apache.xml.resolver.tools.ResolvingXMLReader
Processing file:/home/pubsdm1/jrm29/saxonValidate/instance.xml
resolveSystem(file:/home/pubsdm1/jrm29/saxonValidate/simple.dtd)
resolvePublic(-//MYORG//DTD SIMPLE DTD//EN,file:/home/pubsdm1/jrm29/saxonValidate/simple.dtd)
Resolved public: -//MYORG//DTD SIMPLE DTD//EN
file:/home/pubsdm1/jrm29/saxonValidate/dtd/simple.dtd
Validation error on line 3 column 10 of instance.xml:
XSD99999: Cannot validate <myroot>: no element declaration available
See http://www.w3.org/TR/xmlschema11-1/#cvc-elt clause 1
Validating /myroot[1]
Validation error on line 3 column 10 of instance.xml:
XSD99999: One or more validation errors were reported
Validation unsuccessful
Note that the Catalog resolver successfully resolved the simple.dtd file, but Saxon cannot locate it.
I tried this same validation using oXygen and Saxon-EE by configuring oXygen to use my example catalog.xml and it worked fine.
I will be happy to assist in any troubleshooting and answer any questions you have. Thank you.
Files
Updated by Michael Kay about 10 years ago
The error message from com.saxonica.Validate is because it cannot find a schema (that is, XSD) to validate the document against. There doesn't seem to be any problem with the DTD. The command com.saxonica.Validate is used for schema (XSD) validation, and if you don't have a schema, you shouldn't be using it. To do DTD validation, you don't need Saxon at all, you only need an XML parser, but if you want to do it via Saxon, the simplest way is just to run a query such as
java net.sf.saxon.Query -s:source.xml -qs:name(*) -dtdvalidation:on
plus options to invoke catalog resolution if needed.
Updated by Jason Mihalick about 10 years ago
Thanks, that works. The only change I had to make was instead of using -dtdvalidation:on@, use @-dtd:on
instead
Updated by O'Neil Delpratt almost 10 years ago
- Status changed from New to Closed
Updated by Gregorio Pellegrino 5 months ago
Here you have:
saxon = PySaxonProcessor(license=True)
saxon_source = saxon.parse_xml(xml_file_name="test.html")
saxon.set_configuration_property("http://saxon.sf.net/feature/licenseFileLocation", "saxon-license.lic")
saxon.set_configuration_property("xsdversion", "1.1")
saxon.set_catalog("org/xmlresolver/catalog.xml"))
validator = saxon.new_schema_validator()
validator.set_property("report-node", "true")
validator.set_property("verbose", "false")
validator.register_schema(xsd_file="my_schema.xsd")
validator.validate(xdm_node=saxon_source)
Updated by O'Neil Delpratt 5 months ago
- Description updated (diff)
This I guess should have been added here: https://saxonica.plan.io/issues/6469
Please register to edit this issue