Complex restricting logic in XSD file
-
21-12-2019 - |
Вопрос
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
thenParamName
=UseFilter
,ParamType
=System.Boolean
andParamValue
type boolean; - If
ProcessorName
=NPT Width
thenParamName
=UseFilter
,ParamType
=System.Boolean
andParamValue
typexs:boolean
; - If
ProcessorName
=Finder Width
andParamName
=CMinX
thenParamType
=System.Int32
andParamValue
typexs:integer
; - If
ProcessorName
=Finder Width
andParamName
=CMaxX
thenParamType
=System.Int32
andParamValue
typexs:integer
; - If
ProcessorName
=B Width
thenParamName
=MinX
,ParamType
=System.Int32
andParamValue
typexs:integer
;
and
- If
DeviceParamUpdate
withProcessorName
=NPT Length
is present then must be present that withProcessorName
=NPT Width
DeviceParamUpdate
withProcessorName
=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.
Не связан с StackOverflow