I'm trying to write a code to insert items in exist xml file ,I want the items in file to be like this:
<item>
<title><![CDATA[any title]]></title>
<link>http://any link</link>
<pubDate>any date</pubDate>
<guid isPermaLink="true">any link</guid>
<description><![CDATA[any description]]></description>
<media:credit role="author"><![CDATA[any author]]></media:credit>
<media:category><![CDATA[any category]]></media:category>
<media:content url="http://any link" height="266" width="127" />
<media:thumbnail url="http://any link" height="266" width="127" />
</item>
so I have write this code but it does not give me the same layout:
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)
Dim pubDate = New XElement("pubDate", DateTime.Now.ToString("yyy/MM/dd HH:mm"))
Dim description = New XElement("description", TextBox5.Text)
Dim author = New XElement("media:credit role=", "author" & "><![CDATA[" & TextBox5.Text & "]]>")
Dim category = New XElement("media:category", "<![CDATA[" & TextBox7.Text & "]]>")
Dim content = New XElement("media:content url=", "http://anylink" & " height=" & "266" & " width=" & "127")
Dim thumbnail = New XElement("media:thumbnail url=", "http://anylink" & " height=" & "266" & " width=" & "127")
root.Add(title, link, pubDate, description, author, category, content, thumbnail)
document.Root.Add(root)
document.Save(FilePath)
Label1.Text = "done"
End Sub
I got those errors :
The ':' character, hexadecimal value 0x3A, cannot be included in a name.
The '=' character, hexadecimal value 0x3A, cannot be included in a name.
The ' ' character, hexadecimal value 0x3A, cannot be included in a name.