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?
According to the XML specification, the order of attribute specifications in a start-tag or empty-element tag is not significant.
You can validate your XML documents against XML schemas only; validation against DTDs is not supported. However, although you cannot validate against DTDs, you can insert documents that contain a DOCTYPE or that refer to DTDs.
Simply go to the XML Tools > Validate Now option and click on it. You can also press Ctrl + Alt + Shift + M key combination to open Validate Now option. Now, select the XSD file against which you want to validate the opened XML document. Simply browse and then import the XSD file in the respective field.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With