Solved

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

Posted on 2010-08-15
7
816 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
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.

 
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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 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