473,408 Members | 1,938 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,408 software developers and data experts.

Transoforming XML via XSLT into a string?

I don't do a lot with XML, so I always get a bit lost navigating the XML
classes.

In the past, I've used this:

xslt.Transform(doc, xslArg, Response.Output, Nothing)

Which takes my xml file (doc) and dumps out the XML.

What I'd like to do is isntead of having it just dump the HTML, have it sent
to a string variable.

I'm confused as to how to do that. It seems as if this should work:

Dim doc As System.Xml.XPath.XPathDocument = New
System.Xml.XPath.XPathDocument(XMLfile)
Dim transformedXML As System.IO.TextWriter
xslt.Transform(doc, Nothing, transformedXML)
myString = transformedXML.tostring

but it's not (getting hung up with my xslt.transform line).

What's the proper way to transform an XML file via XSLT and get it as a
string?

-Darrel
Nov 1 '06 #1
2 1490
Hi Darrel,

Thanks for using our products!

The transformation output can be written to a string using a StringWriter.

Please see the sample in the post listed below. At the end of the sample,
the following method is used to output the transformation results to a
StringWriter. Then, the contents of the string can be accessed through the
ToString method of the StringWriter.

myXslDoc.Transform(myXmlDoc, Nothing, myStringWriter)

Console.WriteLine(myStringWriter.ToString())

Example Post
--
http://msdn.microsoft.com/newsgroups...c-07ef58dfe6f0

If you have any questions, comments, or concerns, please don't hesitate to
respond to this post.

Thanks!
Aaron

--
This posting is provided "AS IS" with no warranties, and confers no rights.
--

"darrel" wrote:
I don't do a lot with XML, so I always get a bit lost navigating the XML
classes.

In the past, I've used this:

xslt.Transform(doc, xslArg, Response.Output, Nothing)

Which takes my xml file (doc) and dumps out the XML.

What I'd like to do is isntead of having it just dump the HTML, have it sent
to a string variable.

I'm confused as to how to do that. It seems as if this should work:

Dim doc As System.Xml.XPath.XPathDocument = New
System.Xml.XPath.XPathDocument(XMLfile)
Dim transformedXML As System.IO.TextWriter
xslt.Transform(doc, Nothing, transformedXML)
myString = transformedXML.tostring

but it's not (getting hung up with my xslt.transform line).

What's the proper way to transform an XML file via XSLT and get it as a
string?

-Darrel
Nov 1 '06 #2
Hi Darrel,
>
The transformation output can be written to a string using a StringWriter.

myXslDoc.Transform(myXmlDoc, Nothing, myStringWriter)

Console.WriteLine(myStringWriter.ToString())
ah! StringWRITER. That did it. Thanks!

As a follow-up, can you explain what XMLResolvers are? A lot of the XML
functions say that they are obsolete without an XMLResolver. So I just toss
in a lot of 'NOTHING's which seems to work but I feel that I should better
understsand what the XMLResolvers are actually used for.

-Darrel
Nov 3 '06 #3

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

Similar topics

2
by: Sven | last post by:
Hi I have the following XML & XSLT: XML: <?xml version="1.0" encoding="utf-8"?> <Source Source="IBM"> <Detail> <UserID></UserID>
2
by: Allan Bredahl | last post by:
Hi All I'm trying hard to find out how to transform XML to HTML using XSLT files. I have searched all over for some examples on how to do this, but I have had no succes with any of them. ...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
0
by: Brendan Reynolds | last post by:
I have a web service that takes the XML representation of a dataset and uses XSLT to transform it to the format required to open a disconnected ADODB recordset on the XML, and returns the...
7
by: Doug Heeren | last post by:
I have the following section of VB.NET code that transforms a simple dataset into an Excel xml workbook. It works fine for < 50 rows or so, but I have about 8,000 rows I need to transform. Is there...
3
by: Andy | last post by:
Hi all, I'm having a problem doing an Xslt transform in code. I've done it before, so I'm not really sure why its not working. The problem is that the result of the transform is an empty...
4
by: | last post by:
Hi Guys, I am using XSLT to render my XML dataset at the client side to HTML code. When I am trying to load the XslTransform with an Xslt file, it gives me the following error. >>>> The...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
1
by: Nick | last post by:
I am working on a website for a client and one of their requirements was to have a mailing list. I decided to XSLT to transform "templates" to HTML so that editing was very easy and less time...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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.