質問

Is it possible to validate through schema if combination of element values is unique?

Valid:

<Hardware ID="1">
  <COMPort>COM1</COMPort>
  <BaudRate>9600</BaudRate>
</Hardware>
<Hardware ID="2">
  <COMPort>COM2</COMPort>
  <BaudRate>9600</BaudRate>
</Hardware>
<Hardware ID="3">
  <COMPort>COM1</COMPort>
  <BaudRate>115200</BaudRate>
</Hardware>

Invalid:

<Hardware ID="1">
  <COMPort>COM1</COMPort>
  <BaudRate>9600</BaudRate>
</Hardware>
<Hardware ID="2">
  <COMPort>COM2</COMPort>
  <BaudRate>9600</BaudRate>
</Hardware>
<Hardware ID="3">
  <COMPort>COM1</COMPort>
  <BaudRate>9600</BaudRate>
</Hardware>

This code is invalid because the combination of comport and baudrate is not unique.

役に立ちましたか?

解決

Yes, it is possible: on the element declaration for the parent of the Hardware element, use something like

<xs:unique name="u">
  <xs:selector xpath="Hardware"/>
  <xs:field xpath="COMPort"/>
  <xs:field xpath="BaudRate"/>
</xs:unique>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top