Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting dataset to xml
Message
From
31/10/2005 01:17:52
 
 
To
28/10/2005 02:29:50
General information
Forum:
ASP.NET
Category:
XML
Miscellaneous
Thread ID:
01062521
Message ID:
01063431
Views:
13
Holger,

If Cetin's code worked for you, then I'm guessing you really wanted a string and not UTF8-encoded bytes. If that's the case, you needn't jump through quite so many hoops to get what you want. And also, as you noticed, Cetin's code produced a Diffgram. Here's something a little simpler, without the Diffgram:
private string WriteDataSetToXMLStr(DataSet ds) 
{
	if (ds == null) { return ""; }

	MemoryStream ms = new MemoryStream();
	ds.WriteXml(ms, XmlWriteMode.WriteSchema);

	ms.Seek(0, SeekOrigin.Begin);
	StreamReader sr = new StreamReader(ms);
	string xml = sr.ReadToEnd();

	return xml;
}
~~Bonnie




>
>>   private string WriteDataSetToXMLStr(DataSet ds)
>>   {
>>	if (ds == null) { return String.Empty; }
>>        MemoryStream ms = new MemoryStream();
>>        XmlTextWriter xmlWr = new XmlTextWriter(ms, Encoding.UTF8);
>>	xmlWr.Formatting = Formatting.Indented;
>>	XmlSerializer xs = new XmlSerializer(typeof(DataSet));
>>	xs.Serialize(xmlWr, ds);
>>        ms.Seek(0,SeekOrigin.Begin);
>>        StreamReader sr = new StreamReader(ms);
>>        string xml = sr.ReadToEnd();
>>        sr.Close();
>>	xmlWr.Close();
>>        return xml;
>>   }
>
>
>thanks, it works. Even if I'm not sure, what really happens here. <s>
>But there is still a small problem left.
>The XML, returned by this method, looks like a diffgram!
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform