469,623 Members | 1,800 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

XmlValidatingReader and XML element positions

Hello,

Should the XmlValidatingReader validating xml against an xsd serially
(e.g. - does the XML have to be in the correct position in order for a
document to be valid)?

For example, I am trying to validate an xsd against a sample XML
document and receive errors indicating that there is an invalid child
node in my xml.

XmlValidatingReader complains of the following xml applied to the
following xsd:
<?xml version="1.0" standalone="yes"?>
<Sample xmlns="http://tempuri.org/Sample.xsd">
<Organizations>
<OrganizationID>1</OrganizationID>
<OrganizationName>CIBC</OrganizationName>
<CompanyID>1</CompanyID>
</Organizations>
</Sample>

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Sample" targetNamespace="http://tempuri.org/Sample.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="http://tempuri.org/Sample.xsd"
xmlns:mstns="http://tempuri.org/Sample.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Sample" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Organizations">
<xs:complexType>
<xs:sequence>
<xs:element name="OrganizationID" type="xs:int" />
<xs:element name="CompanyID" type="xs:int" minOccurs="0" />
<xs:element name="OrganizationName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Now, I know that the positions of companyid and organization name are
swapped. Should this detail necessarily fail the document? When I
apply the same schema to a dataset, the dataset loads properly.
Swapping the order of the elements to conform to the schema passes the
validation.

If this validator is sensitive to the position of elements, is there
any way to adjust for this such that the location of the elements is
not as important as the data types and occurances?

Thanks,

Alejandro
Nov 11 '05 #1
1 1721
Alejandro Calbazana wrote:
Should the XmlValidatingReader validating xml against an xsd serially
(e.g. - does the XML have to be in the correct position in order for a
document to be valid)?

Of course, when validating element, whose content is defined using
xs:sequence, which is your case.
xs:sequence requires elements to appear in the same sequence in which they are
declared in schema. If you don't need it, use xs:all or xs:choice instead.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Adam Smith | last post: by
reply views Thread by Harold Putman | last post: by
5 posts views Thread by Geoff | last post: by
1 post views Thread by Bernhard Felkel | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.