我正在使用兩個架構檔案,parent.xsd 和 child.xsd,其中包含父架構。
在父級內部,我通過以下方式定義了一個非常簡單的元素
<xs:element name="parentElement">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="1">
<xs:element ref="another_element" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="firstAttr" type="attrType"/>
</xs:complexType>
</xs:element>
現在,在子模式中,我想覆寫此元素并添加一個新屬性。孩子應該與父母同名。這可以在 XSD 中完成嗎?
我已經嘗試過 <xs:extension> 但我想真正使用相同的父元素而不是基于父元素定義一個新元素。
uj5u.com熱心網友回復:
首先,您需要提取復雜型別。
<xs:element name="parentElement" type="typeOfParentElement"/>
<xs:complexType name="typeOfParentElement">
<xs:sequence minOccurs="0" maxOccurs="1">
<xs:element ref="another_element" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="firstAttr" type="attrType"/>
</xs:complexType>
然后你需要定義一個擴展typeOfParentElement了附加屬性的型別。
然后您需要使用此擴展型別定義子元素的型別。
從您的描述中不清楚子元素是否與父元素同名。如果是,則需要在區域元素宣告而不是全域元素宣告中定義它,因為不能有兩個同名的全域元素。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/383946.html
