5

次のようなXMLドキュメントを受け入れるスキーマを作成したいと思います。

<plugin>
  <label text="blabla" />
  <line />
  <break />
  <textbox name="mytextbox" length="8" required="true" />
  <checkbox name="mycheckbox" checked="true" />
  <combobox name="mycombo">
    <option value="one">Option One</option>
    <option value="two" selected="true">Option One</option>
  </combobox>
  <break />
</plugin>

したがって、プラグインにset {combobox、checkbox、textbox、label、line、break}の要素を含める必要があります。私はこのXSDを作成しましたが、これは間違っています。

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="plugin">
    <xs:complexType>
      <xs:sequence>
       <xs:choice>
        <xs:element name="line" />
        <xs:element name="break" />
        <xs:element name="label">
          <xs:complexType>
            <xs:attribute name="text" type="xs:string" />
            <xs:attribute name="bold" type="xs:boolean" />
            <xs:attribute name="width" type="xs:positiveInteger" />
          </xs:complexType>
        </xs:element>
        <xs:element name="textbox">
          <xs:complexType>
            <xs:attribute name="name" type="xs:string" />
            <xs:attribute name="width" type="xs:positiveInteger" />
            <xs:attribute name="text" type="xs:string" />
            <xs:attribute name="length" type="xs:positiveInteger" />
            <xs:attribute name="required" type="xs:boolean" />
          </xs:complexType>
        </xs:element>
        <xs:element name="combobox">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="option" nillable="true" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:simpleContent msdata:ColumnName="option_Text" msdata:Ordinal="2">
                    <xs:extension base="xs:string">
                      <xs:attribute name="value" type="xs:string" />
                      <xs:attribute name="selected" type="xs:boolean" />
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" />
            <xs:attribute name="width" type="xs:positiveInteger" />
          </xs:complexType>
        </xs:element>
        <xs:element name="checkbox">
          <xs:complexType>
            <xs:attribute name="name" type="xs:string" />
            <xs:attribute name="checked" type="xs:boolean" />
            <xs:attribute name="text" type="xs:string" />
            <xs:attribute name="width" type="xs:positiveInteger" />
          </xs:complexType>
        </xs:element>
       </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="plugin" />
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

私はこのバリデーターツールでそれをテストしました...

しかしそれは言う:

"cvc-complex-type.2.4.d:要素'line'で始まる無効なコンテンツが見つかりました。この時点では子要素は必要ありません。"

だから...何が問題なのですか?このメッセージがわかりません。どの時点でどの子要素ですか?

4

2 に答える 2

5

定義sequenceには子が1つだけあります。つまり、choice

これは、plugin定義した要素のいずれかである可能性がありますが、1つの子のみが許可されることを意味します。

要素を削除し、choiceそのコンテンツをそのままにしておくと、の子になることができる要素の固定シーケンスが作成されますplugin

代わりに、シーケンス要素を削除し、そのコンテンツをそのまま残して、要素に属性追加する場合choice: 、指定した任意の数の子を持つ要素を任意の順序でmaxOccurs="unbounded"検証する必要があります。plugin

于 2011-09-16T09:27:44.550 に答える
1

これにより、シーケンス内で選択を何度も繰り返すことができます。

<xs:complexType>
  <xs:sequence>
   <xs:choice maxOccurs="unbounded">
于 2019-05-20T16:52:34.057 に答える