Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to replace < and & gt coming while creating Xml in asp.net with c#. I am creating an xml and applying signature and adding to the signature node. I need to append <!cONTENTDAta to the content provided. But on creating I am getting <: fro < and >: for >

What I have tried:

string contentdatatag = "<![CDATA[" + content + "]]>";

       string decodedxml = HttpUtility.HtmlDecode(contentdatatag);

       //string decodedxml = contentdatatag.Replace("<", "<").Replace(">", ">");

       XmlNodeList elemList = xmlDoc2.GetElementsByTagName("content");

       elemList[0].InnerText = decodedxml;

      string sdecodedxml= HttpUtility.HtmlDecode(decodedxml);

      elemList[0].InnerText = sdecodedxml;

       XmlNodeList elemList1 = xmlDoc2.GetElementsByTagName("date");

       elemList1[0].InnerText = "2017-04-26T12:21:13";

       content = content + elemList1[0].InnerText;
Posted
Updated 4-May-17 6:27am
Comments
Nirav Prabtani 2-May-17 7:07am    
What is an issue with replace function, Have you checked it ?
george4986 4-May-17 7:37am    
try this
Value = Value.Replace("&lt;", "<");
Value = Value.Replace("&gt;", ">");

1 solution

Try this:
C#
XmlNodeList elemList = xmlDoc2.GetElementsByTagName("content");
if (elemList.Count != 0)
{
    XmlCDataSection cdata = xmlDoc2.CreateCDataSection(content);
    elemList[0].AppendChild(cdata);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900