Subject: xsd conditional validation
Posted By: kapar_p Post Date: 8/3/2006 2:24:21 PM
Is there a way for xml schema to do a conditional validation? Like can XML schema validate the instance of xml document for conditional presence of an element/attribute if another element/attribute exists.



Reply By: mhkay Reply Date: 8/3/2006 3:28:55 PM
No, it's a well-known restriction of XML Schema 1.0 that it can't do this.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: kapar_p Reply Date: 8/4/2006 8:26:00 AM
Thanks for information.
Is there a way around in the current scheme of things like by using XSLT or should we just let the conditional validation be done by DOM or SAX parser.

Reply By: mhkay Reply Date: 8/4/2006 8:32:06 AM
You may be able to define the constraints you want to check using other validation technologies such as Relax NG or Schematron, or you may find it simpler and more flexible to write an XSLT stylesheet to perform validation of your source: write a template rule for each element, check all the necessary conditions, and generate a result document containing the errors.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: kapar_p Reply Date: 8/7/2006 1:48:16 PM
Thanks for providing the alternative to using schema.
I have 2 questions for the 2 alternatives suggested.
1) My instance document is a big XML EDI file and I need to validate and parse it to get data and pass it on to my business logic for further processing. So should I use XSLT and write template rule for each element even if some rules will only validate existence of an element and its datatype or should my stylesheet have only template rules for conditional validation and then schema validate the resulting transformed XML document.
Which would be more efficient? I hope I don't have to parse file again to get the data out from transformed file?

2) My second problem is if I go the RELAX NG way how do I get the schema factory for the schema language RELAX NG.
I tried using the following and it returns null pointer exception.
SchemaFactory sf = SchemaFactory.newInstance(<SCHEMA LANGUAGE>);
<SCHEMA LANGUAGE> could be W3C XML Schema, Relax NG etc.
Does Sun  have an implementation for the RELAX NG schema language.

Thanks





Go to topic 47304

Return to index page 209
Return to index page 208
Return to index page 207
Return to index page 206
Return to index page 205
Return to index page 204
Return to index page 203
Return to index page 202
Return to index page 201
Return to index page 200