2011-07-22 24 views
11

Tôi muốn ghi vào XML dưới các mã đó trong ASP.Net.Tuy nhiên, tôi muốn thêm <![[CDATA]]> vào phần tử thứ năm. khi tôi tạo nó như hình bên dưới, nó tạo ra ""&"bt;" thay vì ký tự >""&"lt;" thay vì < ký tự thành XML. Làm cách nào để loại bỏ vấn đề đó?Làm thế nào để đưa CData vào sử dụng LINQ to XML?

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), 

Trả lời

14

Hãy thử điều này:

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

ở vị trí của hiện tại dòng

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

của bạn.

+0

+1 Điều này đã giúp tôi vô cùng. Cảm ơn! –

Các vấn đề liên quan