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

How to escape text in CSharp console program

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?
Jun 27 '08 #1
3 1756
On Thu, 22 May 2008 15:44:03 +0800, "Alan Mosley" <me@workwrote:
>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.
As an answer to the question "How can I HTMLEncode a string in a
non-ASP application", try adding a reference to System.Web, and use
(e.g.)

string encodedString =
System.Web.HttpUtility.HtmlEncode("a&b");

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

this gives me a_x0026_b I was exspecting a&amp;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?
A question that comes to mind is why you need to escape the data
yourself though - how is your console application creating the XML
file?

Regards,
Gilles.

Jun 27 '08 #2
On May 22, 8:44 am, "Alan Mosley" <me@workwrote:
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
Jun 27 '08 #3
"Alan Mosley" <me@workwrote in
news:#x**************@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.
Jun 27 '08 #4

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

Similar topics

3
by: Ken | last post by:
HI: I'm reading a string that will be displayed in a MessageBox from a resource file. The string in the resource file contains escape sequences so they will be broken up into multiple lines. ...
0
by: Daniel Perron | last post by:
Hi, I was trying to use Galois.Net to specify code generators and I had to look for some text template tool to simplify the syntax. I was looking for something similar to the syntax of an...
16
by: Christine | last post by:
I was wondering if it is possible to read in a text file as a data type other than string. I would like to read it in as some type that handles numbers, like double, or float.
2
by: Tiësto | last post by:
Sometimes I have a string variable with many escaped characters. And when I write ?MyString in the Immediate window, the output is done with the \n \t and similar characteres. Is there any...
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
2
by: ffimbel | last post by:
Hi, I would like to find out the fastest way to concatenate large (200 or 300MB) and numerous (500 - 700) files (Postscript files) into a single one (which can ends up being several GigaB)...
3
by: Trev | last post by:
Hi, I'm learning C# and trying to write the program below, everything works fine until the last section: Console.Write("Would you like to play again y/n: "); again = Console.ReadLine(); if...
1
by: not_a_commie | last post by:
How do you send an escape key to the console? I was trying to change the color of the text in cmd.exe with something like this: Console.Out.Write("\u001b[1;31m"); But that doesn't seem to have...
2
by: | last post by:
I mainly work on OS X, but thought I'd experiment with some Python code on XP. The problem is I can't seem to get these things to work at all. First of all, I'd like to use Greek letters in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
Oralloy
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,...

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.