Question

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.

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top