473,605 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(MapP ath("MyXsl.xsl" ))
trans.Transform (oXmlDataDocume nt, null, Response.Output Stream, 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 (oXmlDataDocume nt, 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.Output Stream 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 4744
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*******@disc ussions.microso ft.com> wrote in message
news:A9******** *************** ***********@mic rosoft.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(MapP ath("MyXsl.xsl" ));
trans.Transform (oXmlDataDocume nt, null, Response.Output Stream, 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 (oXmlDataDocume nt, 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.Output Stream 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.Output Stream and just "flush" to the browser when I'm ready?


What's wrong with transforming directly to Response.Output Stream?
--
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.Tr ansform 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 (myXmlDataDocum ent, 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 (myXmlDataDocum ent, 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.NETFramework SDKv1.1/cpref/html/frlrfsystemxmlx slxsltransformc la
sstransformtopi c14.htm
"Dave" <an*******@disc ussions.microso ft.com> wrote in message
news:78******** *************** ***********@mic rosoft.com...
Thanks, I guess I'm missing something. I'm looking at the XslTransform.Tr ansform 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 (myXmlDataDocum ent, 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
5753
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 the loaded xml document written out on screen - copied it and placed the contents in a physical file and saved it. I then created a simple HTML
6
2477
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 I've hit a snag. How do I resolve multiple external references? The transform method on a stylesheet only takes one resolver, not an array Stephen
4
1547
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 there and I should be able to transform any XML source document I have so that the results would simply contain <root_node/>. I wanted to try that, just so I could see if I understand how this is working and wrote the code and XSL file below. ...
1
3263
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 DataSet or simply to modify the current DataSet. The first part is easy: Dim xmlDataDoc as XmlDataDocument = new XmlDataDocument(oracleDS) Dim xslTrans as XslTransform = new XslTransform
3
1791
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 case i have everything in string
3
1827
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 = doc.CreateNavigator(); XslTransform xslTran = new XslTransform(); xslTran.Load("Transform.XSL"); xslTran.Transform(nav, null, Response.Output, null); This produces me a nice HTML page with enhanced formatting specified
6
2399
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. Having checked the info for XML file reading it suggests that with .net 2.0 you should use the XMLReader class...
0
1136
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 source. In other words, I cannot modify anything about it prior to receiving it. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE UserResponse SYSTEM "UserResponse.dtd"> <UserResponse> <ResponseHeader>
6
2690
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 aXSLFileName, string sOrigXMLContent) {
0
7931
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8411
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8281
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5444
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3911
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2437
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1270
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.