I'm wary that this may generate discussion rather than answers, but nevertheless ...
I currently have an XML that I designed with the primary goal of making it concise and human-readable ... which for me meant favouring attributes over elements and minimizing the vocabulary:
<?xml version='1.0'?>
<Calculation jobId='XI5-332123' user='wombat' time='2009-04-22T14:04:00Z' version='1'>
<Model fileName='Simulate_TestModelSpecifications' processName='Simulate_TestModelSpecifications' password='Simulate_TestModelSpecifications'/>
<Simulation>
<ModelSpecification name='realParam' type='real' value='5.4864'/>
<ModelSpecification name='intParam' type='integer' value='7'/>
<ModelSpecification name='boolParam' type='boolean' value='true'/>
<ModelSpecification name='realArrayParam' type='real' numElements='2'>
<ArrayElement value='1.0'/>
<ArrayElement value='2.0'/>
</ModelSpecification>
<ModelSpecification name='intArrayParam' type='integer' numElements='2'>
<ArrayElement value='5'/>
<ArrayElement value='6'/>
</ModelSpecification>
<ModelSpecification name='boolArrayParam' type='boolean' numElements='2'>
<ArrayElement value='true'/>
<ArrayElement value='false'/>
</ModelSpecification>
<ModelSpecification name='Var1' type='real' value='20.0'/>
<ModelSpecification name='Var2' type='real' numElements='2'>
<ArrayElement value='30.0'/>
<ArrayElement value='40.0'/>
</ModelSpecification>
<ModelSpecification name='scalarSelector' type='string' value='apple'/>
<ModelSpecification name='arraySelector' type='string' numElements='3'>
<ArrayElement value='red'/>
<ArrayElement value='yellow'/>
<ArrayElement value='blue'/>
</ModelSpecification>
<ReportVariable pathName='myUnit.Var1'/>
<ReportVariable pathName='myUnit.Var2(1)'/>
<ReportVariable pathName='myUnit.Var2(2)'/>
</Simulation>
</Calculation>
Now the question has arisen about whether it can be completely validated with an XSD? And if it can't, whether it matters that some of the validation will have to be implemented in the SAX parser (which is also under my control)?
My experience with XML schema is very (very) limited but as far as I can see there are 3 potentially tricky issues with validating this XML:
- The type of the 'value' attribute of an
<ArrayElement>
is controlled by the value of the 'type' attribute of the parent<ModelSpecification>
. - A
<ModelSpecification>
must either have a 'value' attribute or a 'numElements' attribute, but not both. - Only
<ModelSpecification>
s that have a 'numElements' attribute are allowed to contain<ArrayElement>
s and the number of those elements is restricted to the value of that attribute.
So my questions are:
- Am I correct that these 3 cannot be imposed by the XSD?
- Does it matter if I instead impose them in the SAX parser?
Thanks,
Tom