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

Encode a String for Use in XML

Given a string, what's the best way to transform it into an XML friendly
format?

For example, say I have a string like "hulio /<vonNostram <-!"

The less than ("<") and frontslash characters are confusing the third party
program that is receiving this string, since these characters have special
meanings in XML syntax. Is there a quick .NET function that will handle the
XMLizing of strings?

Thanks,

Lamont
Jun 29 '07 #1
3 1655
Lamont,

Don't know if there's a specific _method_ to do this, but if you fill
the "InnerText" property of an System.Xml.XmlNode for example, then
you don't have to worry about escaping it (the setter does the
escaping for you).

Perhaps that helps a little.

Jun 29 '07 #2
On Jun 29, 4:19 pm, "Lamont Sanford" <yaBigDu...@sanford.sonwrote:
Given a string, what's the best way to transform it into an XML
friendly format?
That really depends on how you're creating the XML. There are usually
easy ways of asking the framework to do it as it creates the XML.

Jon

Jun 29 '07 #3
"Lamont Sanford" <ya********@sanford.sonwrote in message
news:j8******************************@giganews.com ...
Given a string, what's the best way to transform it into an XML friendly
format?

For example, say I have a string like "hulio /<vonNostram <-!"

The less than ("<") and frontslash characters are confusing the third
party program that is receiving this string, since these characters have
special meanings in XML syntax. Is there a quick .NET function that will
handle the XMLizing of strings?

Thanks,

Lamont
In NET 3.5 there is a pretty neat solution:

string s = new XText("hulio /<vonNostram <-!").ToString();

- Michael S
Jul 4 '07 #4

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

Similar topics

12
by: Richard Townsend | last post by:
Using Python-2.3.4 on HP-UX11i, the following code: import locale loc = locale.setlocale(locale.LC_ALL) print 'locale =', loc loc = locale.nl_langinfo(locale.CODESET) print 'locale =', loc...
4
by: francescomoi | last post by:
Hi. I'm trying to store a text within a MySQL field (v 3.23.58) by using MySQLdb (v 1.2.1c3). The text is: "telephone..." (note the last character) And I get this error message:...
5
by: Scott Matthews | last post by:
I've recently come upon an odd Javascript (and/or browser) behavior, and after hunting around the Web I still can't seem to find an answer. Specifically, I have noticed that the Javascript...
3
by: Peter | last post by:
Hi, I try to make up a javascript string which contains numeric numbers in any positions. For example, I want to make a string: secretcode, where secretcode.charAt(0)==(-21),...
7
by: jtfaulk | last post by:
I need to encode some information on the server side using ASP.NET with C#; sending via HTTP to a client side application, that needs to be decoded in an MFC C++ application. I'm not sure if I...
7
by: erikcw | last post by:
Hi, I'm trying to build a SQL string sql = """INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d)""", (cid, ag, self.data) It raises this error: AttributeError: 'tuple' object has no...
6
by: 7stud | last post by:
s1 = "hello" s2 = s1.encode("utf-8") s1 = "an accented 'e': \xc3\xa9" s2 = s1.encode("utf-8") The last line produces the error: --- Traceback (most recent call last):
15
by: glacier | last post by:
I use chinese charactors as an example here. "'\\xc4\\xe3\\xba\\xc3\\xc2\\xf0'" My first question is : what strategy does 'decode' use to tell the way to seperate the words. I mean since s1 is...
4
by: J Peyret | last post by:
Well, as usual I am confused by unicode encoding errors. I have a string with problematic characters in it which I'd like to put into a postgresql table. That results in a postgresql error so I...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.