Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2006, 02:24 PM
Registered User
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsd conditional validation

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.



 
Old August 3rd, 2006, 03:28 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old August 4th, 2006, 08:26 AM
Registered User
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old August 4th, 2006, 08:32 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old August 7th, 2006, 01:48 PM
Registered User
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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









Similar Threads
Thread Thread Starter Forum Replies Last Post
create xml with xsd validation obaxe3k XSLT 1 August 13th, 2008 09:43 AM
XML validation with XSD ksskumar XML 0 October 12th, 2007 04:46 AM
XSD validation in non english language rjonk XSLT 1 June 8th, 2006 05:02 PM
Conditional Validation in a DataGrid acorbo ASP.NET 1.0 and 1.1 Professional 0 August 24th, 2004 01:12 PM
xml validation with xsd amolkad XML 0 June 24th, 2004 06:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.