1

I'm triyng to create a schema definition and I have to describe the following scenario:

...
<DeviceParamUpdate>
   <Update>
      <ProcessorName>NPT Length</ProcessorName>
      <ParamName>UseFilter</ParamName>
      <ParamValue>False</ParamValue>
      <ParamType>System.Boolean</ParamType>
   </Update>
</DeviceParamUpdate>
<DeviceParamUpdate>
   <Update>
      <ProcessorName>NPT Width</ProcessorName>
      <ParamName>UseFilter</ParamName>
      <ParamValue>False</ParamValue>
      <ParamType>System.Boolean</ParamType>
   </Update>
</DeviceParamUpdate>
<DeviceParamUpdate>
   <Update>
      <ProcessorName>Finder Width</ProcessorName>
      <ParamName>CMinX</ParamName>
      <ParamValue>-500</ParamValue>
      <ParamType>System.Int32</ParamType>
   </Update>
</DeviceParamUpdate>
<DeviceParamUpdate>
   <Update>
      <ProcessorName>Finder Width</ProcessorName>
      <ParamName>CMaxX</ParamName>
      <ParamValue>1500</ParamValue>
      <ParamType>System.Int32</ParamType>
   </Update>
</DeviceParamUpdate>
<DeviceParamUpdate>
   <Update>
      <ProcessorName>B Width</ProcessorName>
      <ParamName>MinX</ParamName>
      <ParamValue>-1675</ParamValue>
      <ParamType>System.Int32</ParamType>
   </Update>
</DeviceParamUpdate>
...

where

  • If ProcessorName=NPT Length then ParamName=UseFilter, ParamType=System.Boolean and ParamValue type boolean;
  • If ProcessorName=NPT Width then ParamName=UseFilter, ParamType=System.Boolean and ParamValue type xs:boolean;
  • If ProcessorName=Finder Width and ParamName=CMinX then ParamType=System.Int32 and ParamValue type xs:integer;
  • If ProcessorName=Finder Width and ParamName=CMaxX then ParamType=System.Int32 and ParamValue type xs:integer;
  • If ProcessorName=B Width then ParamName=MinX, ParamType=System.Int32 and ParamValue type xs:integer;

and

  • If DeviceParamUpdate with ProcessorName=NPT Length is present then must be present that with ProcessorName=NPT Width
  • DeviceParamUpdate with ProcessorName=Finder Width must both be present or none.

Is there any way to force this type of validations in the XSD file? Thanks in Advance...

Giorgio
  • 1,973
  • 4
  • 36
  • 51

1 Answers1

1

If you're using XML Schema 1.0, you cannot express such constraints in the schema, but you could use Schematron or you could check it at the application level.

If you're using XML Schema 1.1, you can specify co-occurrence constraints via XPath 2.0 using xs:assert.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Sorry but I'm newbie of XSD world. What should I do to use XSD 1.1 instead of XSD 1.0? Can I integrate XSD 1.1 with java and JAXB? Thanks. – Giorgio Jun 04 '14 at 16:40
  • XML processors that support XSD 1.1 include SAXON EE, Altova, and Xerces-J with PsychoPath XPath 2.0. As late as 2011 (and likely still), [JAXB doesn't support XSD 1.1](http://stackoverflow.com/questions/4834664/who-is-using-xml-schema-1-1-version-which-parser-versions-support-it-etc). – kjhughes Jun 04 '14 at 16:51
  • Thanks a lot. Since my knowledge of XSD are not good, I chose to check it at the application level. – Giorgio Jun 05 '14 at 08:03