2012-10-01 57 views
1

有沒有辦法爲元素屬性聲明一個別名?比如我有一個元素<Item>有兩個布爾屬性fooAttributebarAttribute,以別名foobar使得任何以下是有效的:XML屬性別名

<Item foo="true" bar="false" /> 
<Item foo="true" barAttribute="false" /> 
<Item fooAttribute="true" bar="false" /> 
<Item fooAttribute="true" barAttribute="false" /> 
+0

別名是否值得期待?這難道不會解析出數據更難嗎? – Eric

+0

另請參閱http://stackoverflow.com/questions/12460560/defining-an-alias-for-xml-element-in-xsd-schema – Malcolm

回答

2

簡短的回答是不XSD 1.0。如果需要,可以將XSD 1.0與另一種模式語言(RelaxNG或Schematron)結合使用。

在XSD 1.1中,您可以定義屬性的兩種變體,指向某種重用的相同簡單類型,然後定義斷言以使它們互斥。