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="u rn:schemas-microsoft-com:xml-msdata"
xmlns:mstns="Te st.Keystone.Ser vices.Schema.En tityName"
xmlns:msprop="u rn:schemas-microsoft-com:xml-msprop"
xmlns="Test.Key stone.Services. Schema.EntityNa me"
attributeFormDe fault="unqualif ied" elementFormDefa ult="unqualifie d"
targetNamespace ="Test.Keystone .Services.Schem a.EntityName" id="EntityName "
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexTy pe name="EntityNam eTable">
<xs:sequence>
<xs:element msprop:Generato r_UserColumnNam e="EntityNameCo unter"
msprop:Generato r_ColumnPropNam eInRow="EntityN ameCounter"
msprop:Generato r_ColumnVarName InTable="column EntityNameCount er"
msprop:Generato r_ColumnPropNam eInTable="Entit yNameCounterCol umn"
msdata:ReadOnly ="true" msdata:AutoIncr ement="true" form="unqualifi ed"
name="EntityNam eCounter" type="xs:int" />
<xs:element msprop:Generato r_UserColumnNam e="EntityIDCoun ter"
msprop:Generato r_ColumnPropNam eInRow="EntityI DCounter"
msprop:Generato r_ColumnVarName InTable="column EntityIDCounter "
msprop:Generato r_ColumnPropNam eInTable="Entit yIDCounterColum n"
msdata:ReadOnly ="true" form="unqualifi ed" name="EntityIDC ounter"
type="xs:int" />
<xs:element msprop:Generato r_UserColumnNam e="EntityName "
msprop:Generato r_ColumnPropNam eInRow="EntityN ame"
msprop:Generato r_ColumnVarName InTable="column EntityName"
msprop:Generato r_ColumnPropNam eInTable="Entit yNameColumn"
msdata:ReadOnly ="true" form="unqualifi ed" name="EntityNam e">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="200" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="SortName"
msprop:Generato r_ColumnPropNam eInRow="SortNam e"
msprop:Generato r_ColumnVarName InTable="column SortName"
msprop:Generato r_ColumnPropNam eInTable="SortN ameColumn" minOccurs="0"
form="unqualifi ed" name="SortName" >
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="485" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="OtherName"
msprop:Generato r_ColumnPropNam eInRow="OtherNa me"
msprop:Generato r_ColumnVarName InTable="column OtherName"
msprop:Generato r_ColumnPropNam eInTable="Other NameColumn" minOccurs="0"
form="unqualifi ed" name="OtherName ">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="200" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="LookupTitleC ounter"
msprop:Generato r_ColumnPropNam eInRow="LookupT itleCounter"
msprop:Generato r_ColumnVarName InTable="column LookupTitleCoun ter"
msprop:Generato r_ColumnPropNam eInTable="Looku pTitleCounterCo lumn"
minOccurs="0" form="unqualifi ed" name="LookupTit leCounter" type="xs:int" />
<xs:element msprop:Generato r_UserColumnNam e="Forename1"
msprop:Generato r_ColumnPropNam eInRow="Forenam e1"
msprop:Generato r_ColumnVarName InTable="column Forename1"
msprop:Generato r_ColumnPropNam eInTable="Foren ame1Column" minOccurs="0"
form="unqualifi ed" name="Forename1 ">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="Forename2"
msprop:Generato r_ColumnPropNam eInRow="Forenam e2"
msprop:Generato r_ColumnVarName InTable="column Forename2"
msprop:Generato r_ColumnPropNam eInTable="Foren ame2Column" minOccurs="0"
form="unqualifi ed" name="Forename2 ">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="Forename3"
msprop:Generato r_ColumnPropNam eInRow="Forenam e3"
msprop:Generato r_ColumnVarName InTable="column Forename3"
msprop:Generato r_ColumnPropNam eInTable="Foren ame3Column" minOccurs="0"
form="unqualifi ed" name="Forename3 ">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="Forename4"
msprop:Generato r_ColumnPropNam eInRow="Forenam e4"
msprop:Generato r_ColumnVarName InTable="column Forename4"
msprop:Generato r_ColumnPropNam eInTable="Foren ame4Column" minOccurs="0"
form="unqualifi ed" name="Forename4 ">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="Initials"
msprop:Generato r_ColumnPropNam eInRow="Initial s"
msprop:Generato r_ColumnVarName InTable="column Initials"
msprop:Generato r_ColumnPropNam eInTable="Initi alsColumn" minOccurs="0"
form="unqualifi ed" name="Initials" >
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="15" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="Nickname"
msprop:Generato r_ColumnPropNam eInRow="Nicknam e"
msprop:Generato r_ColumnVarName InTable="column Nickname"
msprop:Generato r_ColumnPropNam eInTable="Nickn ameColumn" minOccurs="0"
form="unqualifi ed" name="Nickname" >
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="Honours"
msprop:Generato r_ColumnPropNam eInRow="Honours "
msprop:Generato r_ColumnVarName InTable="column Honours"
msprop:Generato r_ColumnPropNam eInTable="Honou rsColumn" minOccurs="0"
form="unqualifi ed" name="Honours">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="ShortName"
msprop:Generato r_ColumnPropNam eInRow="ShortNa me"
msprop:Generato r_ColumnVarName InTable="column ShortName"
msprop:Generato r_ColumnPropNam eInTable="Short NameColumn" minOccurs="0"
form="unqualifi ed" name="ShortName ">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="200" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="EffectiveFro m"
msprop:Generato r_ColumnPropNam eInRow="Effecti veFrom"
msprop:Generato r_ColumnVarName InTable="column EffectiveFrom"
msprop:Generato r_ColumnPropNam eInTable="Effec tiveFromColumn" minOccurs="0"
form="unqualifi ed" name="Effective From" type="xs:dateTi me" />
<xs:element msprop:Generato r_UserColumnNam e="NatureOfChan ge"
msprop:Generato r_ColumnPropNam eInRow="NatureO fChange"
msprop:Generato r_ColumnVarName InTable="column NatureOfChange"
msprop:Generato r_ColumnPropNam eInTable="Natur eOfChangeColumn " minOccurs="0"
form="unqualifi ed" name="NatureOfC hange">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:maxLength value="100" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element msprop:Generato r_UserColumnNam e="IsConfirme d"
msprop:Generato r_ColumnPropNam eInRow="IsConfi rmed"
msprop:Generato r_ColumnVarName InTable="column IsConfirmed"
msprop:Generato r_ColumnPropNam eInTable="IsCon firmedColumn"
msdata:ReadOnly ="true" form="unqualifi ed" name="IsConfirm ed"
type="xs:boolea n" />
<xs:element msprop:Generato r_UserColumnNam e="DateEffectiv eTo"
msprop:Generato r_ColumnPropNam eInRow="DateEff ectiveTo"
msprop:Generato r_ColumnVarName InTable="column DateEffectiveTo "
msprop:Generato r_ColumnPropNam eInTable="DateE ffectiveToColum n" minOccurs="0"
form="unqualifi ed" name="DateEffec tiveTo" type="xs:dateTi me" />
<xs:element msprop:Generato r_UserColumnNam e="DateEffectiv eFrom2"
msprop:Generato r_ColumnPropNam eInRow="DateEff ectiveFrom2"
msprop:Generato r_ColumnVarName InTable="column DateEffectiveFr om2"
msprop:Generato r_ColumnPropNam eInTable="DateE ffectiveFrom2Co lumn"
minOccurs="0" form="unqualifi ed" name="DateEffec tiveFrom2" type="xs:dateTi me"
/>
<xs:element msprop:Generato r_UserColumnNam e="DateEffectiv eTo2"
msprop:Generato r_ColumnPropNam eInRow="DateEff ectiveTo2"
msprop:Generato r_ColumnVarName InTable="column DateEffectiveTo 2"
msprop:Generato r_ColumnPropNam eInTable="DateE ffectiveTo2Colu mn" minOccurs="0"
form="unqualifi ed" name="DateEffec tiveTo2" type="xs:dateTi me" />
<xs:element msprop:Generato r_UserColumnNam e="CreatedByUse rCounter"
msprop:Generato r_ColumnPropNam eInRow="Created ByUserCounter"
msprop:Generato r_ColumnVarName InTable="column CreatedByUserCo unter"
msprop:Generato r_ColumnPropNam eInTable="Creat edByUserCounter Column"
minOccurs="0" form="unqualifi ed" name="CreatedBy UserCounter" type="xs:int" />
<xs:element msprop:Generato r_UserColumnNam e="DateCreate d"
msprop:Generato r_ColumnPropNam eInRow="DateCre ated"
msprop:Generato r_ColumnVarName InTable="column DateCreated"
msprop:Generato r_ColumnPropNam eInTable="DateC reatedColumn" minOccurs="0"
form="unqualifi ed" name="DateCreat ed" type="xs:dateTi me" />
<xs:element msprop:Generato r_UserColumnNam e="ModifiedByUs erCounter"
msprop:Generato r_ColumnPropNam eInRow="Modifie dByUserCounter"
msprop:Generato r_ColumnVarName InTable="column ModifiedByUserC ounter"
msprop:Generato r_ColumnPropNam eInTable="Modif iedByUserCounte rColumn"
minOccurs="0" form="unqualifi ed" name="ModifiedB yUserCounter" type="xs:int" />
<xs:element msprop:Generato r_UserColumnNam e="DateLastModi fied"
msprop:Generato r_ColumnPropNam eInRow="DateLas tModified"
msprop:Generato r_ColumnVarName InTable="column DateLastModifie d"
msprop:Generato r_ColumnPropNam eInTable="DateL astModifiedColu mn" minOccurs="0"
form="unqualifi ed" name="DateLastM odified" type="xs:dateTi me" />
<xs:element msprop:Generato r_UserColumnNam e="mTimestamp "
msprop:Generato r_ColumnPropNam eInRow="mTimest amp"
msprop:Generato r_ColumnVarName InTable="column mTimestamp"
msprop:Generato r_ColumnPropNam eInTable="mTime stampColumn" minOccurs="0"
form="unqualifi ed" name="mTimestam p" type="xs:base64 Binary" />
</xs:sequence>
<xs:attribute name="RowState" use="optional">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:enumerati on value="Unchange d" />
<xs:enumerati on value="Modified " />
<xs:enumerati on value="Added" />
<xs:enumerati on 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.Schem a.EntityName"
xmlns:mstns="Te st.Keystone.Ser vices.Schema.En tityName"
xmlns="Test.Key stone.Services. Schema.EntityNa me"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
attributeFormDe fault="qualifie d" elementFormDefa ult="qualified" >
<xs:element name="EntityNam e" msdata:IsDataSe t="true"
msdata:UseCurre ntLocale="true" >
<xs:complexType >
<xs:choice minOccurs="0" maxOccurs="unbo unded" />
</xs:complexType>
</xs:element>
</xs:schema>
I have tried using anxmldatadocume nt as follows:
StreamReader myStreamReader = null;
myStreamReader = new StreamReader(@" c:\test.xsd");
XmlDataDocument myXmlDataDocume nt = new XmlDataDocument ();
myXmlDataDocume nt.DataSet.Enfo rceConstraints = true;
myXmlDataDocume nt.DataSet.Name space =
"http://www.w3.org/2001/XMLSchema";
myXmlDataDocume nt.DataSet.Read XmlSchema(myStr eamReader);
I have also tried using a simple dataset with the same result.
Any help with this would be much appreciated.
Lastbuilders