EDN Admin
Well-known member
<p align=left>We are using the XSD annotations supported by SQLXML4 to map an XSD schema to database tables. Prior to doing a Bulk Load, we are using the SQLXML4 annotations in the schema to drive the replacement of human-meaningful type names with database primary key values. To do this, we loaded our schema into an XmlDocument and used XPath expressions to find relevant metadata. Everything worked fine until we began to split up the schema into included parts so that the parts could support other applications. The following code only produces and _xmlSchemaDocument with the Xml represented in the top-level schema without any of the included details:
<p align=left> <font color="#2b91af
<font color="#2b91af XmlSchemaSet</font> xmlSchemaSet = <font color="#0000ff new</font> <font color="#2b91af XmlSchemaSet</font>();
xmlSchemaSet.ValidationEventHandler += ValidationCallBack;
xmlSchemaSet.XmlResolver = <font color="#0000ff new</font> <font color="#2b91af XmlUrlResolver</font>();
<font color="#0000ff using</font> (<font color="#2b91af XmlReader</font> reader = <font color="#2b91af XmlReader</font>.Create(schemaFileName))
{
_xmlSchema = <font color="#2b91af XmlSchema</font>.Read(reader, <font color="#0000ff null</font>); <font color="#008000 // replace null with ValidationEventHandler </font>
<blockquote dir=ltr style="margin-right:0px
<font color="#008000 // create the schema namespace manager </font>
_nameSpaceMgr = <font color="#0000ff new</font> <font color="#2b91af XmlNamespaceManager</font>(reader.NameTable);
reader.Close(); </blockquote>
}<font color="#008000 </font>
xmlSchemaSet.Add(_xmlSchema);
xmlSchemaSet.Compile();
_nameSpaceMgr.AddNamespace(<font color="#a31515 "pbs"</font>, <font color="#a31515 "www.ourcorp.com/SchemaDef/OrderEntry/BaseSchema"</font>);
_nameSpaceMgr.AddNamespace(<font color="#a31515 "xs"</font>, <font color="#a31515 "http://www.w3.org/2001/XMLSchema"</font>);
_nameSpaceMgr.AddNamespace(<font color="#a31515 "sql"</font>, <font color="#a31515 "urn<img alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif chemas-microsoft-com:mapping-schema"</font>);
<font color="#008000 // write the schema to an XmlDocument that can be searched via XPath </font>
<font color="#2b91af StringBuilder</font> sb = <font color="#0000ff new</font> <font color="#2b91af StringBuilder</font>(4048);
<font color="#2b91af XmlWriterSettings</font> settings = <font color="#0000ff new</font> <font color="#2b91af XmlWriterSettings</font>();
settings.Indent = <font color="#0000ff true</font>;
settings.ConformanceLevel = <font color="#2b91af ConformanceLevel</font>.Auto;
<font color="#2b91af XmlWriter</font> writer = <font color="#2b91af XmlWriter</font>.Create(sb, settings);
_xmlSchema.Write(writer, _nameSpaceMgr);
_xmlSchemaDocument.LoadXml(sb.ToString()); </font>
<p align=left>
<p align=left>We have been stumped as to how to derive an XmlDocument with all the included schemas represented.
<p align=left>
<p align=left>We have seen that after the root XmlSchema is added to an XmlSchemaSet, all of the includes are automatically traversed. But and XmlSchema is not searchable via XPath. Stan Kitsis [Walking XmlSchema and XmlSchemaSet objects ] at <a title="http://blogs.msdn.com/stan_kitsis/archive/2005/08/06/448572.aspx http://blogs.msdn.com/stan_kitsis/archive/2005/08/06/448572.aspx http://blogs.msdn.com/stan_kitsis/archive/2005/08/06/448572.aspx presents ways of iterating through objects internal to XmlSchema, but it is much more complicated than searching and XmlDocument representation of the schema with XPath.
<p align=left>
<p align=left>Does anyone know how to convert an XmlSchema with includes into a single XmlDocument with all the includes elaborated?
View the full article
<p align=left> <font color="#2b91af
<font color="#2b91af XmlSchemaSet</font> xmlSchemaSet = <font color="#0000ff new</font> <font color="#2b91af XmlSchemaSet</font>();
xmlSchemaSet.ValidationEventHandler += ValidationCallBack;
xmlSchemaSet.XmlResolver = <font color="#0000ff new</font> <font color="#2b91af XmlUrlResolver</font>();
<font color="#0000ff using</font> (<font color="#2b91af XmlReader</font> reader = <font color="#2b91af XmlReader</font>.Create(schemaFileName))
{
_xmlSchema = <font color="#2b91af XmlSchema</font>.Read(reader, <font color="#0000ff null</font>); <font color="#008000 // replace null with ValidationEventHandler </font>
<blockquote dir=ltr style="margin-right:0px
<font color="#008000 // create the schema namespace manager </font>
_nameSpaceMgr = <font color="#0000ff new</font> <font color="#2b91af XmlNamespaceManager</font>(reader.NameTable);
reader.Close(); </blockquote>
}<font color="#008000 </font>
xmlSchemaSet.Add(_xmlSchema);
xmlSchemaSet.Compile();
_nameSpaceMgr.AddNamespace(<font color="#a31515 "pbs"</font>, <font color="#a31515 "www.ourcorp.com/SchemaDef/OrderEntry/BaseSchema"</font>);
_nameSpaceMgr.AddNamespace(<font color="#a31515 "xs"</font>, <font color="#a31515 "http://www.w3.org/2001/XMLSchema"</font>);
_nameSpaceMgr.AddNamespace(<font color="#a31515 "sql"</font>, <font color="#a31515 "urn<img alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif chemas-microsoft-com:mapping-schema"</font>);
<font color="#008000 // write the schema to an XmlDocument that can be searched via XPath </font>
<font color="#2b91af StringBuilder</font> sb = <font color="#0000ff new</font> <font color="#2b91af StringBuilder</font>(4048);
<font color="#2b91af XmlWriterSettings</font> settings = <font color="#0000ff new</font> <font color="#2b91af XmlWriterSettings</font>();
settings.Indent = <font color="#0000ff true</font>;
settings.ConformanceLevel = <font color="#2b91af ConformanceLevel</font>.Auto;
<font color="#2b91af XmlWriter</font> writer = <font color="#2b91af XmlWriter</font>.Create(sb, settings);
_xmlSchema.Write(writer, _nameSpaceMgr);
_xmlSchemaDocument.LoadXml(sb.ToString()); </font>
<p align=left>
<p align=left>We have been stumped as to how to derive an XmlDocument with all the included schemas represented.
<p align=left>
<p align=left>We have seen that after the root XmlSchema is added to an XmlSchemaSet, all of the includes are automatically traversed. But and XmlSchema is not searchable via XPath. Stan Kitsis [Walking XmlSchema and XmlSchemaSet objects ] at <a title="http://blogs.msdn.com/stan_kitsis/archive/2005/08/06/448572.aspx http://blogs.msdn.com/stan_kitsis/archive/2005/08/06/448572.aspx http://blogs.msdn.com/stan_kitsis/archive/2005/08/06/448572.aspx presents ways of iterating through objects internal to XmlSchema, but it is much more complicated than searching and XmlDocument representation of the schema with XPath.
<p align=left>
<p align=left>Does anyone know how to convert an XmlSchema with includes into a single XmlDocument with all the includes elaborated?
View the full article