How to add schema information into xmldocument from typed dataset

W

Whoever

Hi,

I'm trying to return an XmlDocument or XmlNode converted from a typed
dataset.

public XmlNode whatever() {
MyTypedDataSet ds = new MyTypedDataSet();
return new XmlDataDocument(ds);
}

In WSDL, it shows returned type as xml; in the result, it shows the xml
data.

How do I put schema information in both places?

Thanks.
 
S

Scott M.

You don't have to have all the XML in one XML document.

You can first load up the DataSet with the schema:
dataset.ReadXMLSchema(xmlSchemaNode)
and then read in the data from a different node:
dataset.ReadXML(xmlDataNode)

Be sure to read the schema in first though.
 
W

Whoever

Thanks for the reply. I'm not try to read, but to write. I already have
data in the dataset and trying to return it from a web service as
xmldocument of course.

Just saw there's a ds.WriteXml(????, XmlWriteMode.WriteSchema)

But all examples I can find are trying to write to a file. I need to write
into an XmlNode/XmlDocument/XmlDataDocument and return it.

Of course, it's better to have the schema information in WSDL as well.

Any ideas?
 
D

Dino Chiesa [Microsoft]

The WriteXml method on the DataSet allows you to write to a string or to a
stream.
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataDataSetClassWriteXmlTopic.asp

You do not need to write to a file.

You can also call GetXmlSchema method on the dataset, and put that into a
string.
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdatadatasetclassgetxmlschematopic.asp

Consider using 2 methods - one that returns the schema and one that returns
the data. Either that or put them into different XmlDocuments.



-Dino
 
S

Scott M.

I would use the GetXML and GetXMLSchema methods that return their respective
data as strings.
 
W

Whoever

Thanks again for your follow up.

When returning a string, how can I add the schema information to WSDL so
that the service client have access to the data structure at design time?
 
W

Whoever

Just picked up a message I posted a few days ago where Dan Rogers points
out some confusion I had all these time.

Basically DataSet has type any in WSDL and schema as part of the return data
at run time. The truth is schema information should be in WSDL to
facilitate design time reference. I have already done that through custom
collection, but still kind of stucked with the idea of making schema part of
the return data, which is mostly uneccessary (Excel web query still
complains it has no schema, but I think I'll pass that one).

So seems fine tuning the custom collection with XmlAttribute is a more
practical approach.

Thanks for everyone's help. Really appreicate it.

BTW, if anyone has a good example of using typed dataset and still be able
to have a perfect WSDL, I wouldn't mind rewrite all my codes. Somehow Typed
DataSet always sounds better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top