422,530 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,530 IT Pros & Developers. It's quick & easy.

How to encode special characters in XML document?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.