views:

29

answers:

2

Hi everyone,

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>

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

+1  A: 

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"&gt;
  <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>
Jan
This is a schema for the xml you posted before editing your question.
Jan
Yeah, I know. I'll put it back in. Sorry. But thanks, that did quite a trick. I guess I forgot to specify the ´maxOccurs="X"´ since I wanted to allow from 0 to N...
steff
A: 

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

steff