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

How to encode special characters in XML document?

Hi,
I have a XML document, loaded by

XmlDocument xDoc = new XmlDocument();
xDoc.Load("my.xml");
xPath = xmlKeyName;
XmlNode xNode = xDoc.SelectSingleNode(xPath);

Then I will assign some value to one certain key by:
xNode.InnerXml = "<displayName>" + Name + "</displayName>";

If there are some special characters in my string "Name", such as "&",
"<" or ">", program will raise error. Is there a way I can use to encode all
special characters to eliminate potential problems?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 16 '05 #1
1 9642
Replace '<' with '&lt' and replace '>' with '&gt'. For '&' you could try
using the escape sequence '\&'

Regards
Tarakeshwar

"Hardy Wang" <ha*******@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
Hi,
I have a XML document, loaded by

XmlDocument xDoc = new XmlDocument();
xDoc.Load("my.xml");
xPath = xmlKeyName;
XmlNode xNode = xDoc.SelectSingleNode(xPath);

Then I will assign some value to one certain key by:
xNode.InnerXml = "<displayName>" + Name + "</displayName>";

If there are some special characters in my string "Name", such as "&",
"<" or ">", program will raise error. Is there a way I can use to encode all special characters to eliminate potential problems?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy

Nov 16 '05 #2

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

Similar topics

3
by: fowlertrainer | last post by:
Hi ! I'm hungarian, we use special characters like: á - a' õ -o" etc. I want to encode this characters to in config file I see these characters as \nnn format.
3
by: user | last post by:
hi there has anyone of you writte a function to encode html from like '&' -> '&amp;' and likes to share it with me.. or can anybody give me a hint how to set up something like that. cheers me. ...
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: thomas Armstrong | last post by:
Hi Using Python 2.3.4 + Feedparser 3.3 (a library to parse XML documents) I'm trying to parse a UTF-8 document with special characters like acute-accent vowels: -------- <?xml version="1.0"...
3
by: Bruno | last post by:
Hello, I have a code that generates a xml file and I have some texts that contains " ' < > etc.... how do I encode these texts to have them showed with the characters < " ' / > etc... ...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
6
by: Christian Blackburn | last post by:
Hi Gang, When encoding HTML strings it'll convert things like " --> &rsquo and the like using Server.HTMLEncode(). However, is there a command to make sure strings don't contain valid SQL...
5
by: Oleg.Ogurok | last post by:
Hi there, I need to encode the value of an XML attribute, e.g. string myXml = "<element myAttr=\"" + encodeURIComponent("my \"value") + "\"" ...."; Is there an equivalent of...
5
by: Timothy Madden | last post by:
Hello Is there a function that will allow me to output text written in utf-8 (from db for example) if my document has Content-Type: text/html; charset=ISO-8859-1 I mean htmlspecialchars()...
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:
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.