Validate XML against XSD and ignore order of child elements

I have a method in a C# app that validates a user input XML file against an embedded XSD. It works just fine, but it requires that all the child elements be in the exact order defined in the XSD. To me though, the order doesn't matter so long as the elements exist.

For example, if I had the following XSD...

<xs:element maxOccurs="unbounded" name="ParentElement">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="FirstChildElement" type="xs:string" />
      <xs:element name="SecondChildElement" type="xs:string" />
      <xs:element name="ThirdChildElement" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

And an XML like this...

<ParentElement>
    <FirstChildElement>someValue</FirstChildElement>        
    <ThirdChildElement>someValue</ThirdChildElement>
    <SecondChildElement>someValue</SecondChildElement>
</ParentElement>

If I validated it I'd get an error because the child elements are out of order.

Can I make some change to the XSD so validation only cares if the elements exist, and that they're under the correct parent, but not what order they're in?

Answers


Sequence means, the elements must appear in the specific order. You probably want xs:all. Take a look at http://www.w3schools.com/xml/schema_complex_indicators.asp


Need Your Help

grep: group capturing

regex linux bash grep

I have following string:

jQuery: Check if special characters exists in string

javascript jquery special-characters

I know this question is asked more often here on Stack, but I can't seem to get a straight answer out of the questions already posted.