How to insert new item to channel in XML file
I want to insert new element inside <channel> tag using vb code
my xml file looks like :
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
</channel>
</rss>
this is my code :
Dim root = New XElement("item")
Dim title = New XElement("title", New XCData(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", New XCData(TextBox5.Text))
Dim thumbnail = New XElement("media.thumbnail",
New XAttribute("url", "http://karary-001-site1.htempurl.com/files/" + attac1 + "?itok=YdFLolAU"),
New XAttribute("height", 266),
New XAttribute("width", 127))
root.Add(title, link, pubDate, description, thumbnail)
document.Root.Add(root)
document.Save(FilePath)
my code add new items after channel and rss tag end !!
Re: How to insert new item to channel in XML file
That's because you added it to the document.Root node:
document.Root.Add(root)
So it tacked it onto the end. That's not what you want. You need to find the correct node you want to add the new nodes to, and .add to THAT node.
-tg