473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataSet.ReadXmlSchema and xs:include

Hi All,

I have seen this type of question raised in various groups but no one has supplied a definitive answer. I am trying to load a dataset schema that has an xs:include. Project policy is to have all schemas as embedded resources but there appears to be no means by which the DataSet.ReadXmlSchema method can be induced to use a custom Xmlresolver in order to supply the embedded referenced schema.

I have tried passing a custom resolver to an XmlTextReader and then loading the schema using the reader however the resolver is never fired. I suspect the resolver when used in conjunction with the XmlTextReader is looking for Xml external references such as document("blah") and just sees the <xs:include /> tag as a perfectly legitimate tag for the XSD schema.

I have tried passing the Schema to a XmlSchemaCollection first. This will indeed fire my custom resolver and set up the schema correctly, however there does not appear to be a way to impose this combined schema on the dataset.

I have tried streaming the schema back from the XmlSchemaCollection and then loading it but the <xs:include/> remains as an include tag.

I'm down to performing either a transformation, manual xml munge or even a string replacement to insert the included schema within the parent prior to providing it to the DataSet.ReadXmlSchema method. Ugh!

Any one out there either have an answer or a definitive 'it can't be done' or at least not within a reasonable effort?

Cheers
Patrick Kearney

Sample code only:

DataSet ds = new DataSet()

// lots of options to load schema
// ds.ReadXmlSchema(stream|XmlReader|TextReader|fileP ath|)

// go with XmlTextReader
XmlTextReader rdr = new XmlTextReader(myStream);

// supply my custom resolver that when called knows how to get the
// xsd from the Assembly resources
rdr.XmlResolver = new CustomResolver();

// resolver is not called and schema fails to load because a type is
// not defined (unless the referenced schema is placed within the
// application directory in which case it loads fine, the method must be using
// the XmlUrlResolver under the covers)

ds.ReadXmlSchema(rdr);

// Options to overcome behaviour

// create the reader
XmlTextReader rdr = new XmlTextReader(XSDStream);
XmlSchemaCollection sc = new XmlSchemaCollection();

// load the schema to a collection to force the xs:include to be processed
// custom resolver is called and referenced xsd supplied as a stream
sc.Add("myId", rdr, resolver);

// the schema now has an include collection properly populated with the
// referenced schema, however I can't see a way to pass this schema
// to the dataset
XmlSchema sch = sc["myId"];

// pull out the parent schema
System.Text.StringBuilder sb = new System.Text.StringBuilder();
StringWriter sw = new StringWriter(sb);
sch.Write(sw);
sw.Flush();
// string containing the parent
string parentSchema = sb.ToString();

// pull out the referenced schema
XmlSchemaExternal es = ((XmlSchemaExternal)sch.Includes[0]);
System.Text.StringBuilder sbe = new System.Text.StringBuilder();
StringWriter swe = new StringWriter(sbe);
es.Schema.Write(swe);
swe.Flush();

// string containing the referenced schema
string includeSchema = sbe.ToString();

// I know I could get the contents out more effeciently but this is just to demo,
// from here I could clearly load these strings into xml docs and combine them
// as if they were one schema however this all seems like too much work,
// especially if you consider several levels of referencing.
// Every other schema loading mechanism I have seen in the framework allows
// for a custom resolver to be passed.....what am I missing?

Nov 12 '05 #1
0 3049

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Karl | last post by:
Hi! I'm trying with a really simple test, to use a schema within another, but xmlspy keeps giving me error message: Schema Error - undefined value for 'type' encountered! The file...
4
by: stiank81 | last post by:
Hi. I have a problem witch I assume there is an answear to....? I have several XML schemas, and they all have quiet a lot of definitions in common. They still have to be seperated into...
1
by: David | last post by:
I'm running into problems using XSD.exe to generate classes from XSD files using the <Include> functionality. Being a complete newbie with this, I am obviously missing something obvious I have...
1
by: WStoreyII | last post by:
what exactly is the difference between import and include? For Example if i had a schema called common, that had some common elements that i use such as address, phone ect. And then i created a...
3
by: Nathan Wallace | last post by:
Hello, I have 2 schema, for argument sake let's call them child.xsd and parent.xsd. I define all my types in parent.xsd and the child.xsd include the parent.xsd using the following tag: ...
0
by: John | last post by:
Hi, I'm creating a component to generate a schema file much like VS generates for DataSets. I'm using XmlSchema to do the job and I also am using a XmlNamespaceManager to manage namespaces. ...
2
by: MarkAurit | last post by:
How does one go about getting the information from an .xsd file into a WSDL document? I have a web service that creates a simple object that IBM Websphere can see and use. Great. However, when I...
0
by: Simon Neve | last post by:
Hi, I have several datasets that use exactly the same element. From reading MSDN it appears I can split the common element into its own dataset and use the <xs: include element from any dataset...
2
by: randar | last post by:
I'm having problems getting an XML document to validate against a fairly complex scenario. Goals: -To have two schemas with two different namespaces, so that I can validate each one seperately...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.