473,414 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Transform to a Stream or XmlReader?

Hi,

I have this code that will write the transformed XML immediately to the browser with the Response object..

XslTransform trans = new XslTransform()
trans.Load(MapPath("MyXsl.xsl"))
trans.Transform(oXmlDataDocument, null, Response.OutputStream, null); //Writes immediately to browser her

But if I wanted to return the transformation as a variable and not immediately to the browser, the only way I found to do this was using the XmlReader below..

XmlUrlResolver resolver = new XmlUrlResolver()
XmlReader reader = trans.Transform(oXmlDataDocument, null, resolver)
while (reader.Read())
//Build the XML string here...
Is the XmlReader considered efficient enough or is there another "Stream" type object that I can use instead of the Response.OutputStream and just "flush" to the browser when I'm ready

I've tried declaring a StreamReader or Stream but it wants parameters in the constructor

Any code on this would be helpful. Dave.
Nov 12 '05 #1
5 4734
The XmlReader is very efficient if you want to parse the resulting Xml. If
you just want to write it to a string then you might want to consider
transforming to a StringWriter.

--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor

"Dave" <an*******@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
Hi,

I have this code that will write the transformed XML immediately to the browser with the Response object...
XslTransform trans = new XslTransform();
trans.Load(MapPath("MyXsl.xsl"));
trans.Transform(oXmlDataDocument, null, Response.OutputStream, null); //Writes immediately to browser here
But if I wanted to return the transformation as a variable and not immediately to the browser, the only way I found to do this was using the
XmlReader below...
XmlUrlResolver resolver = new XmlUrlResolver();
XmlReader reader = trans.Transform(oXmlDataDocument, null, resolver);
while (reader.Read()) {
//Build the XML string here....
}

Is the XmlReader considered efficient enough or is there another "Stream" type object that I can use instead of the Response.OutputStream and just
"flush" to the browser when I'm ready?
I've tried declaring a StreamReader or Stream but it wants parameters in the constructor.
Any code on this would be helpful. Dave.

Nov 12 '05 #2
Dave wrote:

Is the XmlReader considered efficient enough or is there another "Stream" type object that I can use instead of the Response.OutputStream and just "flush" to the browser when I'm ready?


What's wrong with transforming directly to Response.OutputStream?
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #3
Thanks, I guess I'm missing something. I'm looking at the XslTransform.Transform overloads but not seeing how you can write to a StringWriter.

Basically, I'm trying to perform a XSL Transform in a Web Service to reformat the XML and make it more readible but I don't know how to return it. I've tried the Transform method to return an XmlReader

XmlReader reader = trans.Transform(myXmlDataDocument, null, resolver);

Then build and return the string out of the reader, but I lose the encoding when I try to run the webservice and display it in the browser. "<" comes back as "&lt;".

Thanks, Dave.
Nov 12 '05 #4
Oleg

Thanks, that seems to be the way to go instead of of all other stuff the DataSet returns. Thanks, Dave.
Nov 12 '05 #5
StringWriter derives from TextWriter, hence you can say:

StringWriter writer = new StringWriter();
string transformedXml = null;
trans.Transform(myXmlDataDocument, null, writer);

transformedXml = writer.ToString();

Also see [0] in the framework SDK docs on your local drive for a full
example.

Keep in mind that string objects always store their content with UTF-16
character encoding. If you need something different you have to write to a
MemoryStream.
--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor

[0]
ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfsystemxmlxslxsltransformcla
sstransformtopic14.htm
"Dave" <an*******@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Thanks, I guess I'm missing something. I'm looking at the XslTransform.Transform overloads but not seeing how you can write to a
StringWriter.
Basically, I'm trying to perform a XSL Transform in a Web Service to reformat the XML and make it more readible but I don't know how to return
it. I've tried the Transform method to return an XmlReader
XmlReader reader = trans.Transform(myXmlDataDocument, null, resolver);

Then build and return the string out of the reader, but I lose the encoding when I try to run the webservice and display it in the browser.
"<" comes back as "&lt;".
Thanks, Dave.

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: B Johnson | last post by:
I am trying to transform an xml document using an xsl document into HTML. I am getting the following error: "There are multiple root elements in the output XML." So I had the contents of...
6
by: Stephen Cook | last post by:
Having worked through the problems around enabling the document function using an XmlUrlResolver I started work on building a useful class to hide the intricacies. Trying to generalise the process...
4
by: Doug | last post by:
I'm learning how to use the XSL transform functionality and can't get it to work. In a book I'm reading on it, it says that I can do like I did below and just add a value like <root_node/> in...
1
by: Geoffrey Gallaway | last post by:
Hello, I'm trying to apply an XSL to a dataset contents. More specifically, I want to apply an XSL to a dataset or an XmlDataDocument and put the resulting transformed data back into another...
3
by: Daniel | last post by:
in C# how do i transform an xml document with an xsl document when my xml document is a string and my xsl document is a string? the msdn examples only show how to do it with steams and files. in my...
3
by: vitaly.tomilov | last post by:
I'm using an ASP.NET form to display data from my database table, and I'm doing it in the following way: XmlDataDocument doc = new XmlDataDocument(mydataSet); XPathNavigator nav =...
6
by: Rob Meade | last post by:
Hi all, I'm having a few difficulties with the above, ie I cant find any good examples anywhere of how to do what I want to do! I have an xml file on my desktop which I want to read in. ...
0
by: K. Wilder | last post by:
I'm having a problem getting this to work in ASP.NET 2.0. I'm trying to prevent the validation of a DTD in the incoming XML. I have this XML that I receive via xml web service from an external...
6
by: Gina_Marano | last post by:
Hey All, I have a string that contains XML content and I want to transform it in new XML content string. What is the best way of doing this? private string DoXSLTransform(string...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.