all groups > dotnet xml > december 2003 >
You're in the

dotnet xml

group:

XMLreader to text


XMLreader to text Bill H
12/29/2003 11:07:39 AM
dotnet xml: How do I read the entire XML text from an XMLReader ?
I just want to retrieve the XML string from a SQL SP formatted as XML. =
I assumed the ExecuteXMLReader was the best option. So whats the most =
streamlined process of getting the XML into a string ?

Thanks
Re: XMLreader to text Oleg Tkachenko
12/29/2003 7:06:42 PM
[quoted text, click to view]

If you don't care about comments and PIs outside root element, all you
need is to move reader to content and read outer XML:

r.MoveToContent();
Console.WriteLine(r.ReadOuterXml());

if you do care about that stuff at roto level, then you can use
something lik ethis:

StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
while (r.Read())
w.WriteNode(r, false);
w.Close();
r.Close();
Console.WriteLine(sw.ToString());

--
Oleg Tkachenko
XML Insider
AddThis Social Bookmark Button