Solved

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

Posted on 2010-08-15
7
802 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now