Subject:"Free format" schema Author:Royce Fickling Date:07 Nov 2005 07:03 PM
I have a XML schema in which I have defined three main data nodes, TimeDomain, Spectrum, & Tachometer. They will be children of the Machine node. These may occur in any order, number, and combination without regard as to the existence of the others. I generate my schema from an existing, known good XML file. When I use this schema to validate another known good XML file which has a different combination of these data nodes, the SS validator considers the second file invalid. My three main data elements may occur in any order and in any combination. There is no specific order or number of the three element types. How can I correctly define this schema? My attached SAMPLE.XML was used to generate my DataImport.xsd. My attached file GBSCIATD.XML file is valid, i.e., satisfies my requirements, but is considered invalid by StylusStudio. Please explain.
Subject:No Topic Author:(Deleted User) Date:08 Nov 2005 09:59 AM
I can suggest 2 solutions to your problem. I recommend solution number 1. Read on.
The fundamental problem is that given a single .xml file, there are many possible .xsd files which MIGHT match your intent. In your case, you might have wanted the 3 elements in a specific order, or in any order, or any number of variations of order and repetition.
The Stylus Studio xsd generator saw the 3 elements in your sample .xml file, and generated a .xsd which requires them to appear in the same order. The critical piece in your .xsd is:
<xs:element maxOccurs="unbounded" ref="Spectrum"/>
Modify it as follows:
<xs:sequence minOccurs="0" maxOccurs="unbounded">
This will permit any number of the 3 elements, in any order.
StylusStudio bundles a 3rd-party tool "Trang" which can read several .xml files at once, and generate a schema which works with all the .xml files. You could run this:
java -jar C:\program files\stylus studio...\bin\trang\trang.jar Sample.xml GBSCIATD.xml output.xsd
That will look at both of the .xml files and generate an .xsd which works with both of them. If you do this, and look at the output.xsd, you will see that it still doesn't satisfy your intent. You will need to provide a larger set of sample .xml files to get the desired result.
For more information on Trang, see http://www.thaiopensource.com/relaxng/trang.html