在XSD 1.1中作業 我有一個模式,其中包括文本元素,我應該用 "關鍵詞 "標簽來標記某些詞。就像這樣:
ex 1:
<text>我有一個<keyword>具體</keyword>味道。</text>
這些關鍵詞既可以像看到的那樣站立,也可以成為一個類別的一部分,該類別被定義為關鍵詞元素中的一個可選屬性。關鍵字要么是指這樣一個類別,要么是將搜索到的關鍵字作為字串放在里面,要么是顯示兩者的組合。
ex 2:
到目前為止還不錯。但現在我應該建立一個條件結構,它也使用這些關鍵詞,但不在文本本身中顯示它們。因此,它被要求只參考它們,就像第二個例子中,只有類別被參考,但關鍵詞元素中沒有字串。這是必須的,因為元素中的所有字串以后都應該被另一個程式讀取。我們的目標是這樣的: ex 3:<
ex 3:
相比之下,像這樣的事情應該是被禁止的,因為 conditioned-keyword-element 里面的字串將顯示在以后應該可讀的字串中: ex 4:
我現在的任務是要在以后顯示在應該可讀的字串中。
我現在的任務是禁止這種結構。我怎樣才能實作這一點呢?在我的模式中,我認為我需要建立一個斷言作為條件元素的一部分,但我不知道如何做。我已經嘗試了幾種方法: ex 5:<
ex 5: ex 6: ex 7: 當我有一個錯誤的XML-Code時,它們都沒有捕捉到這種情況,就像例子4中那樣,或者甚至拋出一個錯誤資訊,說斷言評估失敗。我做錯了什么?我該如何解決這個問題?
uj5u.com熱心網友回復: 我認為這也可以不用斷言(或XSD 1.1):在 uj5u.com熱心網友回復: 如果你知道XPath 2,那就很簡單了:
標籤:<text>我使用的<keyword group='weapon'>sword</keyword>是<keyword>steel</keyword>制成的。
<text><condition><keyword group='words'/><keyword group='handle'/></condition>現在揮動它,純粹的前鋒正在切割我的<keyword>敵人</keyword>。
<text><condition><keyword group='武器'>劍</keyword><keyword group='手柄'/></condition>通過現在揮舞它,純粹的前鋒正在切割我的<keyword>敵人</keyword>.</text><xs: complexType name="condition" mixed="true">
<xs: sequence>
<xs: element name="keyword" type="keyword" minOccurs="1" maxOccurs="5"/>
</xs:sequence>
<xs:assert test="string-length($value) = 0"/span>/>
</xs:complexType>
<xs: complexType name="condition" mixed="true">
<xs: sequence>
<xs: element name="keyword" type="keyword" minOccurs="1" maxOccurs="5"/>
</xs: sequence>
<xs:assert test="$value eq '"/span>/>
</xs:complexType>
<xs: complexType name="condition" mixed="true">
<xs: sequence>
<xs: element name="keyword" type="keyword" minOccurs="1" maxOccurs="5"/>
</xs: sequence>
<xs:assert test="::child:string-length() = 0"/span>/>
</xs:complexType>
condition的復雜型別中的keyword的本地元素宣告可以有一個與keyword的全域定義不同的型別,并且本地定義可以有一個空的內容模型。
<xs: complexType name="condition" mixed="true">
<xs: sequence>
<xs: element name="keyword" type="keyword" minOccurs="1" maxOccurs="5"/>
</xs: sequence>
<xs:assert test="keyword中的每個$keyword滿足string-length($keyword) eq 0"/>
</xs:complexType>
