473,221 Members | 1,765 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,221 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 1749
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.