开发者

XML Schema: how to have multiple identical elements?

I'm having quite a hard time on constructing my 1st XML Schema. I need it to verify the correctness of an XML document that forms a questionnaire.

So here's the section in don't get:

I changed the source. The 1st answer refers to this code:

<root>
    <values>
        <value>Lorem</value>
        <value>ipsum</value>
        <value>dolor</value>
    </values>
</root&g开发者_运维知识库t;

Now my actual goal is this:

<requires>
    <require requires-id="2" type="included">
        <values>  
            <value isRequired="true">Lorem</value>
            <value isRequired="false">Lorem</value>
            <value isRequired="false">Lorem</value>
        </values>
    </require>
    <require requires-id="5" type="excluded">
        <values>  
            <value isRequired="true">Lorem</value>
            <value isRequired="false">Lorem</value>
        </values>
    </require>
</requires>

Can anyone please help to make a proper Schema? I'm using Sun Multi-Schema XML Validator (MSV) to validate the document against the Schema.

Thanks in advance,

Steff


This should do it for the 1st xml:

<xs:complexType name="Values">
    <xs:sequence>
        <xs:element name="value" minOccurs="0" maxOccurs="200">
            <xs:complexType>
                <xs:simpleContent>
                    <xs:extension base="xs:string">
                        <xs:attribute name="isOnlyOption" type="xs:boolean"/>
                    </xs:extension>
                </xs:simpleContent>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
</xs:complexType>
<xs:element name="values" type="Values" minOccurs="0"/>

The 2nd one looks like this:

<xs:element name="requires" minOccurs="0">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="require" minOccurs="1" maxOccurs="200">
                <xs:complexType>
                    <xs:attribute name="requires-id" type="xs:IDREF"/>
                    <xs:attribute name="type" type="RequiresType"/>
                    <xs:all>
                        <xs:element name="values" type="Values" minOccurs="0" maxOccurs="1"/>
                    </xs:all>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Note the reference to the custom data type 'Values' from the 1st snippet.

Thanks,
Steff


I don't know, what should be validated exactly, but the following xml schema would validate for three value tags within a values tag within a root tag. The values has to be strings:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://yourSchema">
  <xsd:element name="root">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="values" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="values">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="value" type="xsd:string" minOccurs="3" maxOccurs="3" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜