M
Mac
I'm trying to validate input from an xml source to a dataset in
dotnet2.0. As far as I can see, type errors correctly cause an
exception, but values that are the correct type but do not satisify
xsd:restriction conditions are ingested without a murmur. Is this a bug
or a feature?
Very frustrating.
Evidence:
1) XML data
<?xml version="1.0" encoding="utf-8"?>
<dataset xmlns="http://tempuri.org/DataSet1.xsd">
<datarow>
<c1>row1</c1>
<c2>5</c2>
</datarow>
<datarow>
<c1>row2</c1>
<c2>10</c2>
</datarow>
</dataset>
2) code fragment to read into a dataset (body of a button click
handler.
protected void Button1_Click(object sender, EventArgs e)
{
XmlReader rdr = new XmlTextReader(Server.MapPath(".\\" +
"XMLfile.xml"));
DataSet dsforload = new DataSet();
dsforload.ReadXmlSchema(Server.MapPath(".\\" +
"App_Code\\DataSet1.xsd"));
dsforload.ReadXml(rdr, XmlReadMode.Auto);
GridView1.DataSource = dsforload;
GridView1.DataBind();
}
3) complete xsd schema; quite a lot of random crap generated by the
'DataSet' wizard of VWD2005 - the interesting bit is at the bottom
xmlns="http://tempuri.org/DataSet1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:annotation>
<xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
<DataSource DefaultConnectionIndex="0"
FunctionsComponentName="QueriesTableAdapter"
Modifier="AutoLayout, AnsiClass, Class, Public"
xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<Connections>
</Connections>
<Tables>
</Tables>
<Sources>
</Sources>
</DataSource>
</xs:appinfo>
</xs:annotation>
<xs:element name="dataset" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true"
msprop:Generator_UserDSName="DataSet1"
msprop:Generator_DataSetName="DataSet1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="datarow"
msprop:Generator_UserTableName="DataTable1"
msprop:Generator_RowDeletedName="DataTable1RowDeleted"
msprop:Generator_TableClassName="DataTable1DataTable"
msprop:Generator_RowChangedName="DataTable1RowChanged"
msprop:Generator_RowClassName="DataTable1Row"
msprop:Generator_RowChangingName="DataTable1RowChanging"
msprop:Generator_RowEvArgName="DataTable1RowChangeEvent"
msprop:Generator_RowEvHandlerName="DataTable1RowChangeEventHandler"
msprop:Generator_TablePropName="DataTable1"
msprop:Generator_TableVarName="tableDataTable1"
msprop:Generator_RowDeletingName="DataTable1RowDeleting">
<xs:complexType>
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:maxInclusive value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
dotnet2.0. As far as I can see, type errors correctly cause an
exception, but values that are the correct type but do not satisify
xsd:restriction conditions are ingested without a murmur. Is this a bug
or a feature?
Very frustrating.
Evidence:
1) XML data
<?xml version="1.0" encoding="utf-8"?>
<dataset xmlns="http://tempuri.org/DataSet1.xsd">
<datarow>
<c1>row1</c1>
<c2>5</c2>
</datarow>
<datarow>
<c1>row2</c1>
<c2>10</c2>
</datarow>
</dataset>
2) code fragment to read into a dataset (body of a button click
handler.
protected void Button1_Click(object sender, EventArgs e)
{
XmlReader rdr = new XmlTextReader(Server.MapPath(".\\" +
"XMLfile.xml"));
DataSet dsforload = new DataSet();
dsforload.ReadXmlSchema(Server.MapPath(".\\" +
"App_Code\\DataSet1.xsd"));
dsforload.ReadXml(rdr, XmlReadMode.Auto);
GridView1.DataSource = dsforload;
GridView1.DataBind();
}
3) complete xsd schema; quite a lot of random crap generated by the
'DataSet' wizard of VWD2005 - the interesting bit is at the bottom
xmlns="http://tempuri.org/DataSet1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:annotation>
<xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
<DataSource DefaultConnectionIndex="0"
FunctionsComponentName="QueriesTableAdapter"
Modifier="AutoLayout, AnsiClass, Class, Public"
xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<Connections>
</Connections>
<Tables>
</Tables>
<Sources>
</Sources>
</DataSource>
</xs:appinfo>
</xs:annotation>
<xs:element name="dataset" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true"
msprop:Generator_UserDSName="DataSet1"
msprop:Generator_DataSetName="DataSet1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="datarow"
msprop:Generator_UserTableName="DataTable1"
msprop:Generator_RowDeletedName="DataTable1RowDeleted"
msprop:Generator_TableClassName="DataTable1DataTable"
msprop:Generator_RowChangedName="DataTable1RowChanged"
msprop:Generator_RowClassName="DataTable1Row"
msprop:Generator_RowChangingName="DataTable1RowChanging"
msprop:Generator_RowEvArgName="DataTable1RowChangeEvent"
msprop:Generator_RowEvHandlerName="DataTable1RowChangeEventHandler"
msprop:Generator_TablePropName="DataTable1"
msprop:Generator_TableVarName="tableDataTable1"
msprop:Generator_RowDeletingName="DataTable1RowDeleting">
<xs:complexType>
<xs:element name="c2" minOccurs="1" ></xs:element>
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:maxInclusive value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>