在XML 1.1中作業。我正在嘗試限制一個包括字串的complexType元素的XML-schema,使其至少有3個字符。我如何做到這一點?
我的目標是擁有一個屬于 complexType 的元素,因此它包括一些進一步的元素以及要使用的屬性。現在的目標是這個元素的內容本身不能是空的。理想情況下,我希望有這樣的東西:<
<
<
<text type='question'><condition extended='playerMoved' keyword='game'/>你是否已經<keyword>move</keyword>?</text>
我想讓一個里面沒有任何文本的元素是無效的,所以像這樣的東西應該是被禁止的:
我現在的問題是,我所嘗試的所有解決方案只適用于simpleTypes,但我無法將它們用于complexType。我已經嘗試了以下想法,但它們都只拋出了錯誤資訊,而且無法編譯: 1.
1.) 對元素本身的限制:
2.) 被simpleContent的復雜型別所限制:
這些都不起作用,而且由于我無法找到通過斷言來實作的方法,我被嚴重卡住了,不知道如何繼續。我怎樣才能讓我的模式有一個至少3個字符的強制性字串呢?
uj5u.com熱心網友回復: 把一個像
標籤:</keyword>?
<text type='question'><condition extended='playerMoved' keyword='game'/></text><xs: element name="text">
<xs:complexType mixed="true">
<xs:simpleContent>
<xs:restriction base='xs:string'/span>>
<xs:minLength value="3"/span>/>
</xs:restriction>/span>
</xs:simpleContent>
<xs:sequence>/span>
<xs: choice minOccurs="0" maxOccurs="unbounded">
<xs: element name="condition" type="condition" minOccurs="0" maxOccurs="unbounded"/>
...
</xs:choice> ...
</xs:sequence>/span>
<xs: attribute name="type" use="required">
<xs:simpleType>
...
</xs:simpleType> ...
</xs:attributee>/span>
</xs:complexType>/span>
</xs: element>
<xs: element name="text">
<xs:complexType mixed="true">
<xs:simpleContent>
<xs:restriction base='textString'/span>>
<xs:minLength value="3"/span>/>
</xs:restriction>/span>
</xs:simpleContent>
<xs:sequence>
...
</xs:sequence> 。
<xs: 屬性 name="type" use="required">
...
</xs:attributee> 。
</xs:complexType>/span>
</xs: element>
...
<xs:complexType name="textString">/span> ...
<xs:simpleContent>
<xs:extension base="xs:string"/>
</xs:simpleContent>/span>
</xs:complexType>/span>
<xs:assert id="test-length" test="string-length() ge 3"></xs:assert>的斷言放入xs:complexType元素。
