Solved

How to create a System.IO.Stream object from an XmlDocument object?

Posted on 2010-08-15
7
861 Views
Last Modified: 2013-11-08
I have the below method that does some transformations and returns an xml document.
I have an in memory xml document and an in memory xsl document. I need to invoke the below method to transform the xml document. How can I create System.IO.Stream objects from the in memory xml documents?

public static XmlDocument Transform(System.IO.Stream xslStream, System.IO.Stream xmlStream)

Thanks for any help.
0
Comment
Question by:ipjyo
[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
  • 4
  • 2
7 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 250 total points
ID: 33442630
Need to use Transform method XslCompiledTransform class . Check:
http://stackoverflow.com/questions/1379475/xslcompiledtransform-output-as-xpathdocument
http://www.15seconds.com/issue/060608.htm
http://msdn.microsoft.com/en-us/library/0610k0w4.aspx

Note: I am not sure what kind of stream objects are the xml/xsl, but the links are clear explaining how to transform it.
0
 

Author Comment

by:ipjyo
ID: 33442777
I think I was not clear with my question.
I needed to use this existing method. I have two in memory xml documents and I need to create a stream objects from these xmls and need to invoke the below method.

public static XmlDocument Transform(System.IO.Stream xslStream, System.IO.Stream xmlStream)

My question is how to create a stream object for an xml document?

Thank you.
0
 

Author Comment

by:ipjyo
ID: 33442783
I have xml documents but this method accepts only parameters of type System.IO.Stream.

public static XmlDocument Transform(System.IO.Stream xslStream, System.IO.Stream xmlStream)
0
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 
LVL 36

Expert Comment

by:Miguel Oz
ID: 33442976
OK, in that case please answer:
1) What kind of objects are your in memory objects? e.g. XmlDocument
2) What kind of stream parameters is you method accepting? e.g. MemoryStream, StreamReader
3) Can you provide implementation code of your transform method to check if there are any limitations?

0
 
LVL 30

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 250 total points
ID: 33443323
Try doing something like:

MemoryStream memStream = new MemoryStream();
xmlDocument.Save(memStream);
memStream.Position = 0;

Same for another (xsl) document. Now you have two streams and may pass them to the function.
0
 

Author Comment

by:ipjyo
ID: 33445342
1) I have XmlDocument objects
2) The method is accepting MemoryStream parameters.
3)
xslStream.Position = 0;
            xmlStream.Position = 0;

            XmlReader xslReader = XmlReader.Create(xslStream);
            XmlReader xmlReader = XmlReader.Create(xmlStream);

            return Transform(xslReader, xmlReader);


Thanks.
0
 

Author Comment

by:ipjyo
ID: 33445350
I tried the way @anarki jimbel showed. It is working for me.

Thanks.
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 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