473,612 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataSet.ReadXml Schema 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.ReadXml Schema 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 XmlSchemaCollec tion 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 XmlSchemaCollec tion 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.ReadXml Schema 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.ReadXmlSchem a(stream|XmlRea der|TextReader| filePath|)

// go with XmlTextReader
XmlTextReader rdr = new XmlTextReader(m yStream);

// 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.ReadXmlSchem a(rdr);

// Options to overcome behaviour

// create the reader
XmlTextReader rdr = new XmlTextReader(X SDStream);
XmlSchemaCollec tion sc = new XmlSchemaCollec tion();

// 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.Str ingBuilder sb = new System.Text.Str ingBuilder();
StringWriter sw = new StringWriter(sb );
sch.Write(sw);
sw.Flush();
// string containing the parent
string parentSchema = sb.ToString();

// pull out the referenced schema
XmlSchemaExtern al es = ((XmlSchemaExte rnal)sch.Includ es[0]);
System.Text.Str ingBuilder sbe = new System.Text.Str ingBuilder();
StringWriter swe = new StringWriter(sb e);
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 3078

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

Similar topics

4
2972
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 PersonGroup.xsd refuses to validate the Person type, even though the include element. I know it finds the Person.xsd file, because I get a "not found" error if I change the schemaLocation value. I thought I was doing everything by the book, I just cant find...
4
2641
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 different XML schemas, but what I want to do is to create one XML schema containing all the common definitions (this is mostly type definitions). I then want all the XML schemas I have to include this file containing the definitions.
1
3054
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 defined two schemas, XMLSchema1 and XMLSchema2 with the same target namespace: "TestSpace", each with one complextype element defined. In the XSD designer for XMLSchema2, I have included XMLSchema1 When I run XSD.exe XSD.exe XMLSchema1.xsd...
1
3358
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 schema called customers to keep track of well customers. how would i use the phone element from the common schema in the customers schema? Would I use import or include or both and if so how? Thanks. WStoreyII
3
2802
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: <xs:include schemaLocation="http://localhost/xsds/parent.xsd"/> Now when I create an XmlSchema object on the child.xsd I couldn't get the type that I define in the parent.xsd. How do I get this? Do I need to create
0
1346
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. XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt); nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); nsmgr.AddNamespace("msdata", "urn:schemas-microsoft-com:xml-msdata"); nsmgr.AddNamespace("mstns",...
2
5658
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 expose a DataSet, Websphere cant use the WSDL document, as it doesnt describe the data elments in the dataset. Im done a lot of readying and looking at posts, and typed datasets sounds like they might be the answer, but I cant figure out how to...
0
977
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 that uses this common element. The datasets are returned from a web service. My question is this: when the web service client uses the datasets which include the common dataset, will this involve another round trip to the server to retrieve the...
2
1916
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 against an XML doc. Hence why I'm using xs:import instead of xs:include. -To create some sample XML that will validate in Visual Studio and I can use the tools there to enter in the XML data.
0
8162
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8415
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6076
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4045
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1413
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.