views:

50

answers:

1

Hello everyone:

I have following XSD code:

<xsd:complexType name="questions">
    <xsd:sequence>
        <xsd:element name="location" type="location"/>
        <xsd:element name="multipleChoiceInput" type="multipleChoiceInput" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element name="textInput" type="textInput" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element name="pictureInput" type="pictureInput" minOccurs="0"/>
    </xsd:sequence>
</xsd:complexType>

The problem here is: the elements location, multipleChoiceInput, etc. must appear in the same order they are declared. I don't want this to happen, I want that, in the validation process the sequence should not be relevant. How can I achieve this?

Another possibility I've tried has been:

<xsd:complexType name="questions">

        <xsd:choice maxOccurs="unbounded">   
            <xsd:element name="location" type="location"/>  
            <xsd:element name="multipleChoiceInput" type="multipleChoiceInput" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="textInput" type="textInput" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="pictureInput" type="pictureInput" minOccurs="0" maxOccurs="1"/>
        </xsd:choice>            

</xsd:complexType>

In this example, the sequence really does not matter anymore, and I can have so much elements as I want (what "all" would not allow me to do). But I still have the Problem with the min- and maxOccurs. In this example, I could have so many "pictureInput"s as possible, what is againt the constraint that I would like to have either 0 or 1.

Thanks a lot for helping!

+3  A: 
<xsd:complexType name="questions">
    <xsd:all>
        <xsd:element name="location" type="location"/>
        <xsd:element name="multipleChoiceInput" type="multipleChoiceInput"/>
        <xsd:element name="textInput" type="textInput"/>
        <xsd:element name="pictureInput" type="pictureInput"/>
    </xsd:all>
</xsd:complexType>

NOTE: I have changed "sequence" to "all"

Sequence forces order (as defined). if order doesn't matter then all is used.

If there are chances of element occurence more than once then xsd:any can be used.

<xsd:complexType name="questions">
    <xsd:sequence>
        <xsd:any minOccurs="0"/>
    </xsd:sequence>
</xsd:complexType>

You can find details of xsd:any at following link:

http://www.w3schools.com/schema/schema_complex_any.asp

YoK
Thanks for answering YoK, but "all" can not be used in my case, cause "all" requires the element to appear only ONCE (min- and maxOccurs can only accept the values 0 and 1).
Then, maybe `<xs:any>` is your friend.
Tomalak
Ya in this case any needs to be used. Will also update answer.
YoK
Thanks again guys, but neither "ANY" nor "ALL" takes following in consideration:1) I want to have, one, and only one, element "location" 2) I want to have 0 or 1 element "pictureInput"... Looking forward other suggestions.
Did you verify that "ALL" doesn't work ?cause on following link it says:he all element provides an XML representation that describes an unordered set of element types. For each element type associated with an all element in an XML Schema Document, there must be a corresponding element in the corresponding XML instance. However, they may appear in the any order. In fact, there may be zero or many elements for each type depending upon the values of the minOccurs and maxOccurs attributes associated with the corresponding element type.http://www.xmlschemareference.com/allElement.html
YoK
Yes YoK, I've tried, and I got following error:Engine name: XercesSeverity: errorDescription: cos-all-limited.2: The {max occurs} of an element in an 'all' model group must be 0 or 1. The value '-1' for element 'multipleChoiceInput' is invalid.Start location: 39:31 (IN THIS CASE maxOccurs has been set to "unbounded")---------------------------------------------------------------------------------------------------------------------------------------------------------------------------This error should be expected, cause "all" does not allow you to set maxOccurs bigger as 1.