0

I'm actually trying to validate an xml file against a schematron one in Java. I hava these following statements:

SchemaFactory factory = SchemaFactory.newInstance("http://www.ascc.net/xml/schematron");

but when i run the program, i get this error:

Exception in thread "main" java.lang.IllegalArgumentException:  No SchemaFactory that implements the schema language specified by: http://www.ascc.net/xml/schematron could be loaded

Can anyone help ? thanks.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
  • I found https://github.com/rahmanusta/Schematron-Validation/blob/master/src/main/java/com/kodcu/Standalone.java which uses `"http://purl.oclc.org/dsdl/schematron"` in the end. However, that Uri comes from a library that provides a `SchemaFactory` https://github.com/ugli/uglisch (and I guess you either need to implement your own or use for example this library) – zapl Oct 30 '14 at 21:27
  • @zapl `http://purl.oclc.org/dsdl/schematron` is the "standard" URI, should be library-unspecific. – lexicore Oct 30 '14 at 21:29
  • @lexicore Thanks, the page it resolves to in a browser seemed odd and I was thinking it is maybe outdated. – zapl Oct 30 '14 at 21:35
  • @zapl URIs used as schema or whatever namespaces or ids often lead to nowhere. I wouldn't even say it is a standard practice for them to lead somewhere. :) So they're not to be opened in browser. – lexicore Oct 30 '14 at 21:42

3 Answers3

2

Alternatively you may use https://github.com/phax/ph-schematron/ for validating XML against SCH files. It offers both "pure" as well as XSLT-based validation.

Philip Helger
  • 1,814
  • 18
  • 28
1

Which version and implementation do you use?

Anyway, try:

http://purl.oclc.org/dsdl/schematron

This was changed in ISO Schematron, http://www.ascc.net/xml/schematron is the old URI.

From the specification:

ISO Schematron now differs from Schematron 1.5 in four practical respects:

  • A new namespace has been adopted using a Persistent URL (PURL), in common with other ISO DSDL languages: http://purl.oclc.org/dsdl/schematron
lexicore
  • 42,748
  • 17
  • 132
  • 221
0

No SchemaFactory that implements the schema

does not necessarily mean that the Uri was wrong (yours it outdated though, see lexicore's answer).

SchemaFactoy is an abstract class and hides the fact that there needs to be a schema specific subclass that understands the schema. There are implementations for the standard Uris / schemas but there seems to be none for schematron's included in a default Java installation.

You can find "instructions" how to provide an implementation of your own in the documentation of the newInstance method

To find a SchemaFactory object for a given schema language, this method looks the following places in the following order[...]

  • [..] system property "javax.xml.validation.SchemaFactory:schemaLanguage" [..]
  • $java.home/lib/jaxp.properties [..]
  • service provider [..] matching javax.xml.validation.SchemaFactory in the resource directory META-INF/services.

The last of the three is probably the most interesting one. http://docs.oracle.com/javase/tutorial/ext/basics/spi.html explains the service provider pattern in java a bit more if you're interested.

But I guess you don't want to implement your own schematron validator, you just want to use one. Try if anything of those two work for you. They came up when using the google to search for ServiceFactory schematron

There might be more out there and there seem to be several other approaches that don't seem use this ServiceFactory path. See Where can I find a Java implementation of an ISO Schematron validator?

Community
  • 1
  • 1
zapl
  • 63,179
  • 10
  • 123
  • 154