How to Include CData using LINQ to XML?

故事扮演 提交于 2020-01-20 05:44:05

问题


I want to record to a XML with below those codes in ASP.Net.However,I want to add <![[CDATA]]> in the fifth element. when I making it as shown below, it's creating ""&"bt;"instead of > character and ""&"lt;"instead of < character to XML. How to get rid of that problem?

Code:

XElement xml = new XElement("photo",
        new XElement("thumbnail", TextBox1.Text),
        new XElement("filename", TextBox2.Text),
        new XElement("baslik1", TextBox3.Text),
        new XElement("baslik2", TextBox4.Text),
        new XElement("description","<>"+TextBox5.Text),
        new XElement("link", TextBox6.Text),
        new XElement("fiyat1", TextBox7.Text),
        new XElement("indorani", TextBox8.Text));

XDocument doc = XDocument.Load(Server.MapPath("~/App_Data/satislar.xml"));

doc.Root.Add(xml);

doc.Save(Server.MapPath("~/App_Data/satislar.xml"));

Response.Write("kayıt eklendi");
new XElement("description","<>"+TextBox5.Text),

回答1:


Try this:

new XElement("description",
    new XCData("<>" + TextBox5.Text)),

in place of your current

new XElement("description", "<>" + TextBox5.Text),

line.



来源:https://stackoverflow.com/questions/6784337/how-to-include-cdata-using-linq-to-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!