Dim FilePath As String
FilePath = "C:\Users\MONZER\Desktop\Karary Web Site\WebApplication1\XMLFile1.xml"
Dim document As New XDocument
If File.Exists(FilePath) Then
document = XDocument.Load(FilePath)
Else
Label1.Text = "not done"
End If
Dim root = New XElement("item")
Dim title = New XElement("title", "<![CDATA[" & TextBox3.Text & "]]>")
Dim link = New XElement("link", TextBox6.Text)
root.Add(title, link)
document.Root.Add(root)
document.Save(FilePath)
Label1.Text = "done"
End Sub
但是它不起作用,请帮帮我!
答案 0 :(得分:3)
这应该有效:
Dim title = New XElement("title", New XCData(TextBox3.Text))
XCData是包装CDATA块的LINQ to XML类。
还有一个alternative syntax:
Dim title = <title><%= New XCData(TextBox3.Text)) %></title>