469,636 Members | 1,527 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,636 developers. It's quick & easy.

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 1355
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sven | last post: by
2 posts views Thread by Allan Bredahl | last post: by
reply views Thread by Christopher M. Lauer | last post: by
reply views Thread by Brendan Reynolds | last post: by
7 posts views Thread by Doug Heeren | last post: by
4 posts views Thread by | last post: by
3 posts views Thread by thomas.porschberg | last post: by
1 post views Thread by Nick | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.