Hi all,
I have a weird problem which has been causing me a headache for the last two
days.
I have to dynamicly generate a schema in memory and load it into a dataset
in memory to be returned for further use.
To create the schema I am using the XMLSchema classes and the result is the
following which compiles successfully:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:mstns="Test.Keystone.Services.Schema.EntityN ame"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"
xmlns="Test.Keystone.Services.Schema.EntityName"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="Test.Keystone.Services.Schema.Ent ityName" id="EntityName"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="EntityNameTable">
<xs:sequence>
<xs:element msprop:Generator_UserColumnName="EntityNameCounter "
msprop:Generator_ColumnPropNameInRow="EntityNameCo unter"
msprop:Generator_ColumnVarNameInTable="columnEntit yNameCounter"
msprop:Generator_ColumnPropNameInTable="EntityName CounterColumn"
msdata:ReadOnly="true" msdata:AutoIncrement="true" form="unqualified"
name="EntityNameCounter" type="xs:int" />
<xs:element msprop:Generator_UserColumnName="EntityIDCounter"
msprop:Generator_ColumnPropNameInRow="EntityIDCoun ter"
msprop:Generator_ColumnVarNameInTable="columnEntit yIDCounter"
msprop:Generator_ColumnPropNameInTable="EntityIDCo unterColumn"
msdata:ReadOnly="true" form="unqualified" name="EntityIDCounter"
type="xs:int" />
<xs:element msprop:Generator_UserColumnName="EntityName"
msprop:Generator_ColumnPropNameInRow="EntityName"
msprop:Generator_ColumnVarNameInTable="columnEntit yName"
msprop:Generator_ColumnPropNameInTable="EntityName Column"
msdata:ReadOnly="true" form="unqualified" name="EntityName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="200" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="SortName"
msprop:Generator_ColumnPropNameInRow="SortName"
msprop:Generator_ColumnVarNameInTable="columnSortN ame"
msprop:Generator_ColumnPropNameInTable="SortNameCo lumn" minOccurs="0"
form="unqualified" name="SortName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="485" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="OtherName"
msprop:Generator_ColumnPropNameInRow="OtherName"
msprop:Generator_ColumnVarNameInTable="columnOther Name"
msprop:Generator_ColumnPropNameInTable="OtherNameC olumn" minOccurs="0"
form="unqualified" name="OtherName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="200" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="LookupTitleCounte r"
msprop:Generator_ColumnPropNameInRow="LookupTitleC ounter"
msprop:Generator_ColumnVarNameInTable="columnLooku pTitleCounter"
msprop:Generator_ColumnPropNameInTable="LookupTitl eCounterColumn"
minOccurs="0" form="unqualified" name="LookupTitleCounter" type="xs:int" />
<xs:element msprop:Generator_UserColumnName="Forename1"
msprop:Generator_ColumnPropNameInRow="Forename1"
msprop:Generator_ColumnVarNameInTable="columnForen ame1"
msprop:Generator_ColumnPropNameInTable="Forename1C olumn" minOccurs="0"
form="unqualified" name="Forename1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="Forename2"
msprop:Generator_ColumnPropNameInRow="Forename2"
msprop:Generator_ColumnVarNameInTable="columnForen ame2"
msprop:Generator_ColumnPropNameInTable="Forename2C olumn" minOccurs="0"
form="unqualified" name="Forename2">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="Forename3"
msprop:Generator_ColumnPropNameInRow="Forename3"
msprop:Generator_ColumnVarNameInTable="columnForen ame3"
msprop:Generator_ColumnPropNameInTable="Forename3C olumn" minOccurs="0"
form="unqualified" name="Forename3">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="Forename4"
msprop:Generator_ColumnPropNameInRow="Forename4"
msprop:Generator_ColumnVarNameInTable="columnForen ame4"
msprop:Generator_ColumnPropNameInTable="Forename4C olumn" minOccurs="0"
form="unqualified" name="Forename4">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="Initials"
msprop:Generator_ColumnPropNameInRow="Initials"
msprop:Generator_ColumnVarNameInTable="columnIniti als"
msprop:Generator_ColumnPropNameInTable="InitialsCo lumn" minOccurs="0"
form="unqualified" name="Initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="15" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="Nickname"
msprop:Generator_ColumnPropNameInRow="Nickname"
msprop:Generator_ColumnVarNameInTable="columnNickn ame"
msprop:Generator_ColumnPropNameInTable="NicknameCo lumn" minOccurs="0"
form="unqualified" name="Nickname">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="Honours"
msprop:Generator_ColumnPropNameInRow="Honours"
msprop:Generator_ColumnVarNameInTable="columnHonou rs"
msprop:Generator_ColumnPropNameInTable="HonoursCol umn" minOccurs="0"
form="unqualified" name="Honours">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="ShortName"
msprop:Generator_ColumnPropNameInRow="ShortName"
msprop:Generator_ColumnVarNameInTable="columnShort Name"
msprop:Generator_ColumnPropNameInTable="ShortNameC olumn" minOccurs="0"
form="unqualified" name="ShortName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="200" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="EffectiveFrom"
msprop:Generator_ColumnPropNameInRow="EffectiveFro m"
msprop:Generator_ColumnVarNameInTable="columnEffec tiveFrom"
msprop:Generator_ColumnPropNameInTable="EffectiveF romColumn" minOccurs="0"
form="unqualified" name="EffectiveFrom" type="xs:dateTime" />
<xs:element msprop:Generator_UserColumnName="NatureOfChange"
msprop:Generator_ColumnPropNameInRow="NatureOfChan ge"
msprop:Generator_ColumnVarNameInTable="columnNatur eOfChange"
msprop:Generator_ColumnPropNameInTable="NatureOfCh angeColumn" minOccurs="0"
form="unqualified" name="NatureOfChange">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="100" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generator_UserColumnName="IsConfirmed"
msprop:Generator_ColumnPropNameInRow="IsConfirmed"
msprop:Generator_ColumnVarNameInTable="columnIsCon firmed"
msprop:Generator_ColumnPropNameInTable="IsConfirme dColumn"
msdata:ReadOnly="true" form="unqualified" name="IsConfirmed"
type="xs:boolean" />
<xs:element msprop:Generator_UserColumnName="DateEffectiveTo"
msprop:Generator_ColumnPropNameInRow="DateEffectiv eTo"
msprop:Generator_ColumnVarNameInTable="columnDateE ffectiveTo"
msprop:Generator_ColumnPropNameInTable="DateEffect iveToColumn" minOccurs="0"
form="unqualified" name="DateEffectiveTo" type="xs:dateTime" />
<xs:element msprop:Generator_UserColumnName="DateEffectiveFrom 2"
msprop:Generator_ColumnPropNameInRow="DateEffectiv eFrom2"
msprop:Generator_ColumnVarNameInTable="columnDateE ffectiveFrom2"
msprop:Generator_ColumnPropNameInTable="DateEffect iveFrom2Column"
minOccurs="0" form="unqualified" name="DateEffectiveFrom2" type="xs:dateTime"
/>
<xs:element msprop:Generator_UserColumnName="DateEffectiveTo2"
msprop:Generator_ColumnPropNameInRow="DateEffectiv eTo2"
msprop:Generator_ColumnVarNameInTable="columnDateE ffectiveTo2"
msprop:Generator_ColumnPropNameInTable="DateEffect iveTo2Column" minOccurs="0"
form="unqualified" name="DateEffectiveTo2" type="xs:dateTime" />
<xs:element msprop:Generator_UserColumnName="CreatedByUserCoun ter"
msprop:Generator_ColumnPropNameInRow="CreatedByUse rCounter"
msprop:Generator_ColumnVarNameInTable="columnCreat edByUserCounter"
msprop:Generator_ColumnPropNameInTable="CreatedByU serCounterColumn"
minOccurs="0" form="unqualified" name="CreatedByUserCounter" type="xs:int" />
<xs:element msprop:Generator_UserColumnName="DateCreated"
msprop:Generator_ColumnPropNameInRow="DateCreated"
msprop:Generator_ColumnVarNameInTable="columnDateC reated"
msprop:Generator_ColumnPropNameInTable="DateCreate dColumn" minOccurs="0"
form="unqualified" name="DateCreated" type="xs:dateTime" />
<xs:element msprop:Generator_UserColumnName="ModifiedByUserCou nter"
msprop:Generator_ColumnPropNameInRow="ModifiedByUs erCounter"
msprop:Generator_ColumnVarNameInTable="columnModif iedByUserCounter"
msprop:Generator_ColumnPropNameInTable="ModifiedBy UserCounterColumn"
minOccurs="0" form="unqualified" name="ModifiedByUserCounter" type="xs:int" />
<xs:element msprop:Generator_UserColumnName="DateLastModified"
msprop:Generator_ColumnPropNameInRow="DateLastModi fied"
msprop:Generator_ColumnVarNameInTable="columnDateL astModified"
msprop:Generator_ColumnPropNameInTable="DateLastMo difiedColumn" minOccurs="0"
form="unqualified" name="DateLastModified" type="xs:dateTime" />
<xs:element msprop:Generator_UserColumnName="mTimestamp"
msprop:Generator_ColumnPropNameInRow="mTimestamp"
msprop:Generator_ColumnVarNameInTable="columnmTime stamp"
msprop:Generator_ColumnPropNameInTable="mTimestamp Column" minOccurs="0"
form="unqualified" name="mTimestamp" type="xs:base64Binary" />
</xs:sequence>
<xs:attribute name="RowState" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Unchanged" />
<xs:enumeration value="Modified" />
<xs:enumeration value="Added" />
<xs:enumeration value="Deleted" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:schema>
I am then convert this to s string and try to load this into a dataset using
the LoadXMLSchema property but when I read the schema after accepting changes
in the dataset the result is:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="EntityName"
targetNamespace="Test.Keystone.Services.Schema.Ent ityName"
xmlns:mstns="Test.Keystone.Services.Schema.EntityN ame"
xmlns="Test.Keystone.Services.Schema.EntityName"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="EntityName" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded" />
</xs:complexType>
</xs:element>
</xs:schema>
I have tried using anxmldatadocument as follows:
StreamReader myStreamReader = null;
myStreamReader = new StreamReader(@"c:\test.xsd");
XmlDataDocument myXmlDataDocument = new XmlDataDocument();
myXmlDataDocument.DataSet.EnforceConstraints = true;
myXmlDataDocument.DataSet.Namespace =
"http://www.w3.org/2001/XMLSchema";
myXmlDataDocument.DataSet.ReadXmlSchema(myStreamRe ader);
I have also tried using a simple dataset with the same result.
Any help with this would be much appreciated.
Lastbuilders