I'd like to be able to transform some XML I have in memory first, then write it out to a file, as opposed to writing it to a file, transforming it and writing it to the same file like below. Again, I don't want to have to do it like shown below, where I
wrote my non formatted xml to "myxml.xml", then instantiated a new transform and transformed the same file I just wrote out.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("myfile.xslt");
xslt.Transform("myxml.xml", "myxml.xml");
using (FileStream fs = new FileStream("xx.xml",FileMode.OpenOrCreate))
{
XslCompiledTransform x = new XslCompiledTransform();
x.Load("xx.xslt");
XmlTextReader xreader = new XmlTextReader(fs);
XmlTextWriter xwriter = new XmlTextWriter("c:\\yyy.xml",Encoding.UTF8);
x.Transform(xreader, xwriter);
xwriter.Close();
xreader.Close();
}
Thank you for responding. Isn't xx.xml a file that has to exist in the file system first in order to create a new filestream object? What I am looking for is to make a large xml file in memory, then write it out in many xml files. Something more like
this:
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("myfile.xslt");
xslt.Transform(<in memory xml>, "myxml.xml");
attrib75
Member
367 Points
218 Posts
XslCompiledTransform in memory, without input file
Aug 17, 2012 08:58 PM|LINK
I'd like to be able to transform some XML I have in memory first, then write it out to a file, as opposed to writing it to a file, transforming it and writing it to the same file like below. Again, I don't want to have to do it like shown below, where I wrote my non formatted xml to "myxml.xml", then instantiated a new transform and transformed the same file I just wrote out.
XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("myfile.xslt"); xslt.Transform("myxml.xml", "myxml.xml");Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: XslCompiledTransform in memory, without input file
Aug 19, 2012 02:01 AM|LINK
Hi,
You have to use XmlTextReader and XmlTextWriter:
using (FileStream fs = new FileStream("xx.xml",FileMode.OpenOrCreate))
{
XslCompiledTransform x = new XslCompiledTransform();
x.Load("xx.xslt");
XmlTextReader xreader = new XmlTextReader(fs);
XmlTextWriter xwriter = new XmlTextWriter("c:\\yyy.xml",Encoding.UTF8);
x.Transform(xreader, xwriter);
xwriter.Close();
xreader.Close();
}
attrib75
Member
367 Points
218 Posts
Re: XslCompiledTransform in memory, without input file
Aug 20, 2012 12:47 PM|LINK
Thank you for responding. Isn't xx.xml a file that has to exist in the file system first in order to create a new filestream object? What I am looking for is to make a large xml file in memory, then write it out in many xml files. Something more like this:
XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("myfile.xslt"); xslt.Transform(<in memory xml>, "myxml.xml");Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: XslCompiledTransform in memory, without input file
Aug 20, 2012 11:51 PM|LINK
I'm afraid (as far as I see……) you cannot do that directly……
attrib75
Member
367 Points
218 Posts
Re: XslCompiledTransform in memory, without input file
Sep 06, 2012 01:11 PM|LINK
Ok thanks for your help. Any chance Microsoft will implement this?