Question posted by: =?Utf-8?B?TGFzdGJ1aWxkZXJz?=
(Guest)
on
June 27th, 2008 07:20 PM
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.EntityName"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"
xmlns="Test.Keystone.Services.Schema.EntityName"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="Test.Keystone.Services.Schema.EntityName" 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="EntityNameCounter"
msprop:Generator_ColumnVarNameInTable="columnEntityNameCounter"
msprop:Generator_ColumnPropNameInTable="EntityNameCounterColumn"
msdata:ReadOnly="true" msdata:AutoIncrement="true" form="unqualified"
name="EntityNameCounter" type="xs:int" />
<xs:element msprop:Generator_UserColumnName="EntityIDCounter"
msprop:Generator_ColumnPropNameInRow="EntityIDCounter"
msprop:Generator_ColumnVarNameInTable="columnEntityIDCounter"
msprop:Generator_ColumnPropNameInTable="EntityIDCounterColumn"
msdata:ReadOnly="true" form="unqualified" name="EntityIDCounter"
type="xs:int" />
<xs:element msprop:Generator_UserColumnName="EntityName"
msprop:Generator_ColumnPropNameInRow="EntityName"
msprop:Generator_ColumnVarNameInTable="columnEntityName"
msprop:Generator_ColumnPropNameInTable="EntityNameColumn"
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="columnSortName"
msprop:Generator_ColumnPropNameInTable="SortNameColumn" 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="columnOtherName"
msprop:Generator_ColumnPropNameInTable="OtherNameColumn" 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="LookupTitleCounter"
msprop:Generator_ColumnPropNameInRow="LookupTitleCounter"
msprop:Generator_ColumnVarNameInTable="columnLookupTitleCounter"
msprop:Generator_ColumnPropNameInTable="LookupTitleCounterColumn"
minOccurs="0" form="unqualified" name="LookupTitleCounter" type="xs:int" />
<xs:element msprop:Generator_UserColumnName="Forename1"
msprop:Generator_ColumnPropNameInRow="Forename1"
msprop:Generator_ColumnVarNameInTable="columnForename1"
msprop:Generator_ColumnPropNameInTable="Forename1Column" 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="columnForename2"
msprop:Generator_ColumnPropNameInTable="Forename2Column" 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="columnForename3"
msprop:Generator_ColumnPropNameInTable="Forename3Column" 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="columnForename4"
msprop:Generator_ColumnPropNameInTable="Forename4Column" 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="columnInitials"
msprop:Generator_ColumnPropNameInTable="InitialsColumn" 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="columnNickname"
msprop:Generator_ColumnPropNameInTable="NicknameColumn" 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="columnHonours"
msprop:Generator_ColumnPropNameInTable="HonoursColumn" 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="columnShortName"
msprop:Generator_ColumnPropNameInTable="ShortNameColumn" 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="EffectiveFrom"
msprop:Generator_ColumnVarNameInTable="columnEffectiveFrom"
msprop:Generator_ColumnPropNameInTable="EffectiveFromColumn" minOccurs="0"
form="unqualified" name="EffectiveFrom" type="xs:dateTime" />
<xs:element msprop:Generator_UserColumnName="NatureOfChange"
msprop:Generator_ColumnPropNameInRow="NatureOfChange"
msprop:Generator_ColumnVarNameInTable="columnNatureOfChange"
msprop:Generator_ColumnPropNameInTable="NatureOfChangeColumn" 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="columnIsConfirmed"
msprop:Generator_ColumnPropNameInTable="IsConfirmedColumn"
msdata:ReadOnly="true" form="unqualified" name="IsConfirmed"
type="xs:boolean" />
<xs:element msprop:Generator_UserColumnName="DateEffectiveTo"
msprop:Generator_ColumnPropNameInRow="DateEffectiveTo"
msprop:Generator_ColumnVarNameInTable="columnDateEffectiveTo"
msprop:Generator_ColumnPropNameInTable="DateEffectiveToColumn" minOccurs="0"
form="unqualified" name="DateEffectiveTo" type="xs:dateTime" />
<xs:element msprop:Generator_UserColumnName="DateEffectiveFrom2"
msprop:Generator_ColumnPropNameInRow="DateEffectiveFrom2"
msprop:Generator_ColumnVarNameInTable="columnDateEffectiveFrom2"
msprop:Generator_ColumnPropNameInTable="DateEffectiveFrom2Column"
minOccurs="0" form="unqualified" name="DateEffectiveFrom2" type="xs:dateTime"
/>
<xs:element msprop:Generator_UserColumnName="DateEffectiveTo2"
msprop:Generator_ColumnPropNameInRow="DateEffectiveTo2"
msprop:Generator_ColumnVarNameInTable="columnDateEffectiveTo2"
msprop:Generator_ColumnPropNameInTable="DateEffectiveTo2Column" minOccurs="0"
form="unqualified" name="DateEffectiveTo2" type="xs:dateTime" />
<xs:element msprop:Generator_UserColumnName="CreatedByUserCounter"
msprop:Generator_ColumnPropNameInRow="CreatedByUserCounter"
msprop:Generator_ColumnVarNameInTable="columnCreatedByUserCounter"
msprop:Generator_ColumnPropNameInTable="CreatedByUserCounterColumn"
minOccurs="0" form="unqualified" name="CreatedByUserCounter" type="xs:int" />
<xs:element msprop:Generator_UserColumnName="DateCreated"
msprop:Generator_ColumnPropNameInRow="DateCreated"
msprop:Generator_ColumnVarNameInTable="columnDateCreated"
msprop:Generator_ColumnPropNameInTable="DateCreatedColumn" minOccurs="0"
form="unqualified" name="DateCreated" type="xs:dateTime" />
<xs:element msprop:Generator_UserColumnName="ModifiedByUserCounter"
msprop:Generator_ColumnPropNameInRow="ModifiedByUserCounter"
msprop:Generator_ColumnVarNameInTable="columnModifiedByUserCounter"
msprop:Generator_ColumnPropNameInTable="ModifiedByUserCounterColumn"
minOccurs="0" form="unqualified" name="ModifiedByUserCounter" type="xs:int" />
<xs:element msprop:Generator_UserColumnName="DateLastModified"
msprop:Generator_ColumnPropNameInRow="DateLastModified"
msprop:Generator_ColumnVarNameInTable="columnDateLastModified"
msprop:Generator_ColumnPropNameInTable="DateLastModifiedColumn" minOccurs="0"
form="unqualified" name="DateLastModified" type="xs:dateTime" />
<xs:element msprop:Generator_UserColumnName="mTimestamp"
msprop:Generator_ColumnPropNameInRow="mTimestamp"
msprop:Generator_ColumnVarNameInTable="columnmTimestamp"
msprop:Generator_ColumnPropNameInTable="mTimestampColumn" 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.EntityName"
xmlns:mstns="Test.Keystone.Services.Schema.EntityName"
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