472,982 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 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 3026

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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.