Yet another special character problem
-
-
Hi When I pass & to the function putnodeValue() under the IXMLDom, its converting it to &. The same thing happens for &gr; also, when &gr; is passed the value set is &gr. How to avoid this, I want the exact value to be set which I am passing. Pls help
http://www.w3.org/TR/2004/REC-xml-20040204/#charsets[^] The following quoted from that page: The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings "&" and "<" respectively. The right angle bracket (>) MAY be represented using the string ">", and MUST, for compatibility, be escaped using either ">" or a character reference when it appears in the string "]]>" in content, when that string is not marking the end of a CDATA section. -- modified at 23:46 Friday 26th May, 2006
-
http://www.w3.org/TR/2004/REC-xml-20040204/#charsets[^] The following quoted from that page: The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings "&" and "<" respectively. The right angle bracket (>) MAY be represented using the string ">", and MUST, for compatibility, be escaped using either ">" or a character reference when it appears in the string "]]>" in content, when that string is not marking the end of a CDATA section. -- modified at 23:46 Friday 26th May, 2006
Actually my problem is I am reading a CSV file and conveting it into XML, when one of the comma seperated value is &. I read it and set the value to the XML using IXMLDomNode's put_nodeValue() function in VC++. But the resulting output is &. Similarly when I pass > its converted to > How to over come this problem, the put_nodeValue() function is converting & to & Is there any escape sequence to be added so that & is read as & Thanks in Advance
-
Actually my problem is I am reading a CSV file and conveting it into XML, when one of the comma seperated value is &. I read it and set the value to the XML using IXMLDomNode's put_nodeValue() function in VC++. But the resulting output is &. Similarly when I pass > its converted to > How to over come this problem, the put_nodeValue() function is converting & to & Is there any escape sequence to be added so that & is read as & Thanks in Advance
If your source data contains an "&", it will be converted to "&" and placed into your XML document. When you parse your XML document, the "&" will be converted back to a "&". However, you must use CDATA to store "&" as is:
using System; using System.Collections.Generic; using System.Text; using System.Xml; namespace AmpXml { class Program { static void Main(string[] args) { XmlDocument doc = new XmlDocument(); XmlNode node = doc.CreateNode( XmlNodeType.Element, "amps", string.Empty); doc.AppendChild(node); node = doc.CreateNode( XmlNodeType.Element, "amp", string.Empty); doc.DocumentElement.AppendChild(node); XmlCDataSection cdata = doc.CreateCDataSection( "&&>>&&<<&&"); node.AppendChild(cdata); Console.WriteLine(doc.OuterXml); } } }
-- modified at 13:00 Saturday 27th May, 2006