Solved

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

Posted on 2010-08-15
7
825 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
  • 4
  • 2
7 Comments
 
LVL 35

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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 35

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 29

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

790 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