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. 5 4755
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.
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
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 "<".
Thanks, Dave.
Oleg
Thanks, that seems to be the way to go instead of of all other stuff the DataSet returns. Thanks, Dave.
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 "<". Thanks, Dave. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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
|
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. ...
|
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
|
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
| |
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
|
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...
|
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>
|
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)
{
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |