?
Solved

Need to return the XML from a Dataset as a string from a C# method

Posted on 2014-03-07
3
Medium Priority
?
402 Views
Last Modified: 2014-03-10
I need to return as a string the XML from a DataSet

Stream returnXML = new MemoryStream();
            returnDS.WriteXml(returnXML);                       
            return returnXML   //How do I convert this to a return string?

Open in new window

0
Comment
Question by:Bruce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Assisted Solution

by:MajorBigDeal
MajorBigDeal earned 900 total points
ID: 39913486
I didn't compile this but hopefully it will point you in a good direction:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(responseReader);

StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
xmlTextWriter.Formatting = Formatting.Indented; // remove if pretty print not wanted
xmlDoc.WriteTo(xmlTextWriter);
xmlTextWriter.Flush();
return stringWriter.ToString();
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 800 total points
ID: 39913492
Use the DataSet method GetXml() as follows.

return returnDS.GetXml();

Therefor no need for the memory stream.
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 300 total points
ID: 39913511
You can use the Encoding class for this:

e.g.

using System.Text;

...

returnXML.Position = 0;

return Encoding.UTF8.GetString(returnXML.ToArray());

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question