Solved

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

Posted on 2010-08-15
7
835 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

735 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