![](/img/trans.png)
[英]XSD - How to allow elements in any order any number of times in XML?
[英]How to allow any number of any attributes with XSD?
如何實現簡單的<table>
標簽與 XSD 匹配?
以下不起作用:
<xs:element name="table">
<xs:complexType>
<xs:sequence>
<xs:element name="tr" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="td"
minOccurs="0"
maxOccurs="unbounded"
type="MixedTemplateContentContainer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>
如果我在 table 標簽中使用任何屬性,它會失敗:
<table ccc="table" bgcolor="#ffffff">
<tr align="center"><td>
說
屬性 'ccc' 不允許出現在元素 'table' 中。
我用 Saxon 模式處理器運行了這個,並得到了錯誤消息
test.xml 第 1 行的驗證錯誤:XSD99999:與屬性 @ccc 匹配的<xs:anyAttribute>
需要嚴格驗證,但沒有可用的屬性聲明
本質上, <xs:anyAttribute>
有一個processContents
屬性,默認值是嚴格的,這意味着你可以使用任何你喜歡的屬性,前提是模式中有一個匹配的屬性聲明。 您可能想要 processContents="lax" 或 "skip"。 值 lax 意味着如果模式包含一個匹配的屬性聲明,則該屬性將根據匹配的屬性聲明進行驗證,否則無論如何都被接受。 值跳過意味着任何屬性都被接受而無需驗證。
你的問題是什么? 是嗎
如何使用 XSD 允許任意數量的任何屬性?
或
如何用XSD實現簡單的標簽匹配?
因為它們看起來完全不同的問題。
第一個的答案是使用xs:anyAttribute
。
將<xs:anyAttribute>
元素的processContents屬性設置為skip
:
<xs:anyAttribute processContents="skip" />
^^^^^^^^^^^^^^^^^^^^^^
制作完整的 XSD:
<xs:element name="table">
<xs:complexType>
<xs:sequence>
<xs:element name="tr" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="td"
minOccurs="0"
maxOccurs="unbounded"
type="MixedTemplateContentContainer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.