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:
Expand|Select|Wrap|Line Numbers
- <?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>
Expand|Select|Wrap|Line Numbers
- <?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>
The code for loading the schema and the XML is pretty basic:
Expand|Select|Wrap|Line Numbers
- xmlDS = new DataSet();
- xmlDS.ReadXmlSchema(@”EAN.XSD”);
- xmlDS.ReadXml(@”EAN.XML”);
- this.dataGridView1.DataSource = xmlDS.Tables["MEASUREMENT"];