Results 1 to 2 of 2

Thread: How to insert new item to channel in XML file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2018
    Posts
    17

    Exclamation 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 !!

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width