0
Answer

ADO.NET schema validation bug?

cpruim

cpruim

17y
1.9k
1

Hello,

Am I doing something wrong or is it a bug?
What I’m trying to do is this:
I create a dataset. Load a schema, read my XML and bind the dataset to a datagridview.

Not too complicated, but the thing is that the XML is not validated the way I want it to be validated.

What I want is an XML file with exactly 18 digits. The schema looks like this:
[CODE]
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns="" finalDefault="" id="BLA" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element msdata:IsDataSet="true" msdata:Locale="en-US" name="BLA">
    <xs:complexType>
      <xs:choice minOccurs="1" maxOccurs="unbounded">
        <xs:element name="MEASUREMENT">
          <xs:complexType>
            <xs:sequence minOccurs="1" maxOccurs="1">
              <xs:element minOccurs="1" maxOccurs="1" block="restriction" name="EANCODE">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:pattern value="([0-9])*" />
                    <xs:minLength value="18" />
                    <xs:maxLength value="18" />
                    <xs:whiteSpace value="collapse" />
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>
[/CODE]

The XML file looks like this. I adapted the XML data a little to force a validation error, but it doesn’t seem like it is validating at all except when I put in a 19 digit string.
[CODE]
<?xml version="1.0" standalone="yes"?>
<BLA>
  <MEASUREMENT>
    <EANCODE>123456789012345678</EANCODE>
  </MEASUREMENT>
  <MEASUREMENT>
    <EANCODE>12345678901234567</EANCODE>
  </MEASUREMENT>
  <MEASUREMENT>
    <EANCODE>12345678901234567A</EANCODE>
  </MEASUREMENT>
  <MEASUREMENT>
    <EANCODE>123456789012345678</EANCODE>
  </MEASUREMENT>
</BLA>
[/CODE]


The code for loading the schema and the XML is pretty basic:
[CODE]
xmlDS = new DataSet();

xmlDS.ReadXmlSchema(@”EAN.XSD”);
xmlDS.ReadXml(@”EAN.XML”);

this.dataGridView1.DataSource = xmlDS.Tables["MEASUREMENT"];
[/CODE]

Does anyone have a clue?