Вопрос

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...

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top