1

I want to validate an XML file against RELAXNG schema provided. Searching on the net gave me hints to create a Schema instance using SchemaFactory by providing the appropriate Schema Language. So as per my requirement I used:

SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);

But the following exception was thrown at run:

Exception in thread "main" java.lang.IllegalArgumentException: No SchemaFactory that implements the schema language specified by: http://relaxng.org/ns/structure/1.0 could be loaded
at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:207)

I am using Java6 and observed that only 'W3C_XML_SCHEMA_NS_URI' works. Rest all the schema URIs throws the similar exception.

I am fairly new to using the XML validation APIs. Can someone please provide me the appropriate usage in case I am not doing it correctly?

Thanks & Regards,
Keya

5 Answers5

2

RNG is poorly supported in Java APIs, it never really got traction. I know of no Java API implementations that handle it. I suggest converting the schema to XML Schema (using Trang or similar) and then validating against that.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • Hi, Thanks for the reply. I used as you suggested Trang to convert the rng to xsd. But I get error running it. Following is the command with the error: $ java -jar trang.jar -I rng -O xsd config_schema.rng config_schema.xsd xml-validation/trang-20081028/config_schema.rng:1:1: fatal: Content is not allowed in prolog. $ Can you provide me some suggestion on the above error? –  Jul 22 '09 at 08:11
  • Make sure there's no whitespace or comments between the start of the the file and the start of the schema definition. – skaffman Jul 22 '09 at 08:50
  • Thanks. Apart from whitespaces I was also using the .rng extension instead of .rnc. Using the right extension converted the RNG Schema to XSD. –  Jul 24 '09 at 06:50
0

RNG is not supported as widely as XML Schema. You should always think of using XSD first.

T0xicCode
  • 4,583
  • 2
  • 37
  • 50
0

msv is in Java; I suppose it has a clear API you can use, but I've only ever used it on the command line and in scripts.

reinierpost
  • 8,425
  • 1
  • 38
  • 70
0

Kohsuke Kawaguchi apparently wrote a adapter library for jaxp to use a relaxng validator, see here and here

Valentin Rocher
  • 11,667
  • 45
  • 59
0

I've had success in validating a document against a XML-based RelaxNG Schema using Java 6, check out :

How to validate an XML document using a RELAX NG schema and JAXP?

Don't know if it's relevant, just pointing out :-).

Community
  • 1
  • 1
Dr1Ku
  • 2,875
  • 3
  • 47
  • 56