[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

How to escape text in CSharp console program

ThatsIT.net.au

5/22/2008 7:44:00 AM

I have a console app, that creates a xml file, I need to escape the data
before dumping it in the xml file.

I would use Server.HTMLEncode if it was ASP.NET.

I tried System.Xml.XmlConvert.EncodeName("a&b")

this gives me a_x0026_b I was exspecting a&b

Maybe thios is ok. the xml file is a google sitemap, it need to be read by
google bot, will it read a_x0026_b as a&b I dont know.

any help, ideas?


2 Answers

Jon Skeet

5/22/2008 8:52:00 AM

0

On May 22, 8:44 am, "Alan Mosley" <me@work> wrote:
> I have a console app, that creates a xml file, I need to escape the data
> before dumping it in the xml file.

How are you creating the file? If you're just explicitly writing each
part of it to disk, why not use all the built-in XML APIs, e.g. build
up an XmlDocument and save that. It's a lot simpler than working out
where to encode what, IMO.

Jon

Arnout Grootveld

5/22/2008 9:00:00 AM

0

"Alan Mosley" <me@work> wrote in
news:#xHdd#9uIHA.1240@TK2MSFTNGP02.phx.gbl:

> I have a console app, that creates a xml file, I need to escape the
> data before dumping it in the xml file.
>
> I would use Server.HTMLEncode if it was ASP.NET.

It sounds like you're using strings to build up your XML. You might want to
consider using one of the XML API's -- that will take care of entity-fying
magic characters, and will probably also give you fewer issues w.r.t.
encodings.

However, if you want to stick to the string-based approach, take a look at
System.Web.HttpUtility.HtmlEncode.


--
Arnout.