Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Yet another special character problem

Yet another special character problem

Scheduled Pinned Locked Moved XML / XSL
helptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arrun
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • A Arrun

      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

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • G George L Jackson

        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

        A Offline
        A Offline
        Arrun
        wrote on last edited by
        #3

        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 &amp;. Similarly when I pass > its converted to &gt; 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

        G 1 Reply Last reply
        0
        • A Arrun

          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 &amp;. Similarly when I pass > its converted to &gt; 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

          G Offline
          G Offline
          George L Jackson
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups