문제

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