Có thể định nghĩa trong Lược đồ XML một điều kiện dựa trên giá trị thuộc tính không? Ví dụ: khi [email protected]="one"
, tôi muốn one-element
được phép và bắt buộc hoặc khi [email protected]="two"
, tôi muốn two-element
được cho phép và bắt buộc.Điều kiện dựa trên giá trị thuộc tính (Lược đồ XML)
Ví dụ, chứng từ hợp lệ là:
<root>
<test attrib="one"/>
<some-element-1/>
<some-element-2/>
...
<some-element-n/>
<one-element>
</one-element>
</root>
hoặc
<root>
<test attrib="two"/>
<some-element-1/>
<some-element-2/>
...
<some-element-n/>
<two-element>
</two-element>
</root>
tài liệu sai:
<root>
<test attrib="one"/>
<some-element-1/>
<some-element-2/>
...
<some-element-n/>
</root>
hoặc
<root>
<test attrib="two"/>
<some-element-1/>
<some-element-2/>
...
<some-element-n/>
<one-element>
</one-element>
</root>
Có thể trong XSD không?
Vì vậy, tôi cũng cần định nghĩa ' ' hai lần cho mỗi trường hợp? –
Pol
Không, bạn có thể xác định một loại đã biết ở cấp cơ sở lược đồ và tái sử dụng nó. Vui lòng xem cập nhật của tôi. –
Cảm ơn. Để định nghĩa hai kiểu nên tôi sử dụng 'xs: attribute' (với thuộc tính' fixed') và 'xs: choice'? – Pol