0

XMLスキーマを開発しようとしています。これは調査用であり、XMLの例は次のようになります。

<survey>
  <instructions>Please complete the survey.</instructions>
  <section>
    <sectionHeader>Multiple Choice: Select the most appropriate answer.</sectionHeader>
    <item>
      <question>What is your favorite color?</question>
      <answer>
        <option>red</option>
        <option>yellow</option>
        <option>blue</option>
      </answer>
    </item>
    <item>
      <question>What is your favorite shape?</question>
      <answer>
        <option>circle</option>
        <option>square</option>
        <option>triangle</option>
      </answer>
    </item>
  </section>
  <section>
    <sectionHeader>Free Response: Type a Response</sectionHeader>
    <item>
      <question>Who is your idol and why?</question>
      <answer>
        <textbox>Type your answer here.</textbox>
      </answer>
    </item>
  <section>
</survey>

基本的に、回答には1つ以上のオプション、または1つのテキストボックスを含めることができます。また、調査には1つ以上のセクションが含まれている必要があり、各セクションには1つ以上の項目を含めることができます。私は現在、次のxmlスキーマを持っています。

<xs:element name="survey">
  <xs:complexType>
    <xs:element name="instructions" type="xs:string"/>
    <xs:element name="section">
      <xs:complexType>
        <xs:element name="sectionHeader" type="xs:string"/>
        <xs:element name="item"/>
          <xs:complexType>
            <xs:element name="question" type="xs:string"/>
            <xs:element name="answer">
              ?? Choice between multiple options or one text box ??
            </xs:element>
          </xs:complexType>
        </xs:element>
      </xs:complexType>
    </xs:element>
  </xs:complexType>
</xs:element>

ただし、これでは1つのセクションと1つのアイテムしか使用できません。これらのタグの1つ以上を順番に許可するようにしたい。また、回答タグに1つ以上のオプションまたは1つのテキストボックスを含める必要があります。これどうやってするの?

4

1 に答える 1

1

xs:elementパーティクルのグループはxs:choiceまたはxs:sequence内にグループ化する必要があり、xs:elementまたはxs:choice / xs:sequenceのいずれかでminOccursとmaxOccursを指定できます。したがって、シーケンス(セクション、アイテム、セクション、アイテム、...)が必要な場合は、

<xs:sequence minOccurs="1" maxOccurs="unbounded">
  <xs:element name="section"/>
  <xs:element name="item"/>
</xs:sequence>
于 2012-05-17T10:21:50.637 に答える