MemoryStream into String

I

info

I'm battling here..
I have transformed some XML using XSL, and need to output the result
as a string...
But I can't get the MemorySteram converted to a String...
Can someone assist?

I have this:
public string GenerateMenu()
{
string outputXml = string.Empty;
// Load the master XML File...
XPathDocument masterMenu = new XPathDocument(MasterXMLMenu);

//Load the Transformation XSL document...
XslTransform masterTransformer = new XslTransform();
masterTransformer.Load(MasterXSLMenu);

MemoryStream xmlStream = new MemoryStream();

masterTransformer.Transform(masterMenu, null, xmlStream);

....

Now I need to transfor xmlStream to String type...

Can you assist?
 
I

info

StreamReader.ReadToEnd() should do it.

Pete

Just tried that, Pete. Thanks, but no joy..

............

masterTransformer.Transform(masterMenu, null, xmlStream);

StreamReader sr = new StreamReader(xmlStream);

return sr.ReadToEnd();

Comes up with a blank. I notice 'REadToEnd reads from the Current
position... Should I be ensureing that the current position is the
BOF? At the moment, I am returning nothing.
 
D

DrewCE

Off the top of my head, I can think of....

string s =
Encoding.Default.GetString(xmlStream.GetBuffer(),0,xmlStream.Length);

-Drew
 
A

Arne Vajhøj

I'm battling here..
I have transformed some XML using XSL, and need to output the result
as a string...
But I can't get the MemorySteram converted to a String...
Can someone assist?

I have this:
public string GenerateMenu()
{
string outputXml = string.Empty;
// Load the master XML File...
XPathDocument masterMenu = new XPathDocument(MasterXMLMenu);

//Load the Transformation XSL document...
XslTransform masterTransformer = new XslTransform();
masterTransformer.Load(MasterXSLMenu);

MemoryStream xmlStream = new MemoryStream();

masterTransformer.Transform(masterMenu, null, xmlStream);

...

Now I need to transfor xmlStream to String type...

Use StringWriter wrapped in XmlTextWriter instead of MemoryStream
(StringWriter has a convenient ToString method).

Arne
 
M

Mr. Arnold

I'm battling here..
I have transformed some XML using XSL, and need to output the result
as a string...
But I can't get the MemorySteram converted to a String...
Can someone assist?

I have this:
public string GenerateMenu()
{
string outputXml = string.Empty;
// Load the master XML File...
XPathDocument masterMenu = new XPathDocument(MasterXMLMenu);

//Load the Transformation XSL document...
XslTransform masterTransformer = new XslTransform();
masterTransformer.Load(MasterXSLMenu);

MemoryStream xmlStream = new MemoryStream();

masterTransformer.Transform(masterMenu, null, xmlStream);

...

Now I need to transfor xmlStream to String type...

Can you assist?


You make a String Method call ConvertToStringXML or something, you pass it
the MemoryStream, and you return the string out of it, by using the
StreamReader.peek method and a Loop.

I had to do something similar, that is, get the XML in a MemoryStream out of
it and converted to string.

I am sure you'll put it together or find the article that I used.

http://www.google.com/search?hl=en&q=streamreader.peek+method&btnG=Google+Search
 

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

Top