Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2004

Tip: Looking for answers? Try searching our database.

DataSet.ReadXml - where the schema name is?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RA - 23 Nov 2004 17:03 GMT
Hi

I have an xml schema and I have created a dataset from that schema.
I have a web service that recieve info and sends back an xml information.
I send back the xml using SchemaDataset.WriteXml (...)
A consumer of the web service then call a different method of the web
service which takes an xml string as an input parameter.
I need to load this xml string into the Schemadataset. I do that using the
following:

SchemaDataset.ReadXml (...)

My question is:

I assume that the dataset validated the xml string agianst its schema - well
then where does the dataset gets the schema from?
Here is the info that the web service method gets

<MyDatasetSchema xmlns=http://www.myweb.com/schema/MyDatasetSchema.xsd>
<StoreList>
 <StoreId>5</StoreId>
   </StoreList>
   </MyDatasetSchema >

   Thanks
Drew Marsh - 23 Nov 2004 19:09 GMT
> I assume that the dataset validated the xml string agianst its schema
> - well
> then where does the dataset gets the schema from?

Well the problem is that that assumption is unfortunately wrong. If you wanted to validate the schema you need to put a XmlValidatingReader in the middle of your call to ReadXml. The next problem is, that if you want it to validate specific schemas you need to hook up a custom XmlResolver that helps locate those schemas. The default implementation tries to chase down namespaces URIs, but if the URI isn't a URL (or a URL that it supports natively) then it can't. Therefore you'll probably want to store the schemas in a well known location for your app and have a custom XmlResolver help resolve the schemas from that location.

So you end up with something like so:

<codeSnippet language="C#">
public void MyWebMethod(XmlElement incomingElement)
{
 XmlValidatingReader reader = new XmlValidatingReader(new XmlNodeReader(incomingElement));
 reader.XmlResolver = new MyCustomXmlResolver();

 MyTypedDataSet myDataSet = new MyTypedDataSet();

 XmlDataDocument dataDocument = new XmlDataDocument(myDataSet);
 dataDocument.Load(reader);

 ... use dataset ...
}
</codeSnippet>

Now all that's left to do is to write MyCustomXmlResolver. For more details on writing a custom XmlResolver, have a look at this artcile on MSDN[1].

HTH,
Drew

[1] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conCreatingCustomResolver.asp


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.