471,108 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

encoding xml when you don't want it to go to a file

Hi,

I'm trying to create a chunk of XML where I want all the entities to be
encoded properly. However, I don't really want to use XmlTextWriter
because I don't want to XML to go into a file on disk.

Is there a simple utility method which will atke a string and an
encoding and encode it as XML properly such that it could then be
included in a CDATA section in an XML document?

Is it possible to use the XmlWriter base class and redirect output to a
string variable? Or would creating an XML DOM object in emmory be the
best way to go?

Thanks

Simon

Oct 11 '06 #1
2 1615
Simon Kittle wrote:
I'm trying to create a chunk of XML where I want all the entities to be
encoded properly. However, I don't really want to use XmlTextWriter
because I don't want to XML to go into a file on disk.

Is there a simple utility method which will atke a string and an
encoding and encode it as XML properly such that it could then be
included in a CDATA section in an XML document?

Is it possible to use the XmlWriter base class and redirect output to a
string variable?
Sure.

StringWriter sw = new StringWriter();
XmlWriter w = XmlWriter.Create(sw);
....
w.Close();
string xml = sw.ToString();
--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Oct 11 '06 #2
sweet,

cheers man

Oleg Tkachenko [MVP] wrote:
Simon Kittle wrote:
I'm trying to create a chunk of XML where I want all the entities to be
encoded properly. However, I don't really want to use XmlTextWriter
because I don't want to XML to go into a file on disk.

Is there a simple utility method which will atke a string and an
encoding and encode it as XML properly such that it could then be
included in a CDATA section in an XML document?

Is it possible to use the XmlWriter base class and redirect output to a
string variable?

Sure.

StringWriter sw = new StringWriter();
XmlWriter w = XmlWriter.Create(sw);
...
w.Close();
string xml = sw.ToString();
--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Oct 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Sebastian Meyer | last post: by
10 posts views Thread by Christopher H. Laco | last post: by
6 posts views Thread by jmgonet | last post: by
2 posts views Thread by jmhmaine | last post: by
6 posts views Thread by kath | last post: by
23 posts views Thread by Allan Ebdrup | last post: by
3 posts views Thread by LiMBi | last post: by

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.