VB.Net - XML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Webdesigner29
    New Member
    • Apr 2008
    • 2

    VB.Net - XML

    Hello,

    I wasn't sure if this should go in the XML or .Net section but since it's the .Net code I'm querying I figure this is the right spot. I'm trying to add to an XML file using VB.net on an ASP.Net web site. Right now, I'm using 3 text boxes on a page that would have the "title", "descriptio n", and "link". I'm able to add information to these text boxes and when I click the submit button it updates the XML but overwrites the original content. What I'm trying to do is append the xml with new content and place it at the beginning of the original content because the original content will get older and this is for new changes to the site.

    Here is my xml code:

    <?xml version="1.0" encoding="UTF-8"?>
    <rss>
    <channel>
    <item id="1">
    <title>Test Title</title>
    <description>Th is is a test link</description>
    <link>http://www.msn.com</link>
    </item>
    </channel>
    <item />
    </rss>


    Here is my source code:

    Protected Sub btnSend_Click(B yVal sender As Object, ByVal e As System.Web.UI.I mageClickEventA rgs) Handles btnSend.Click

    'Declarations
    Dim loXMLDoc As XmlDocument = New XmlDocument
    Dim loNode As XmlNode
    Dim loNode2 As XmlNode
    Dim loNode3 As XmlNode

    loXMLDoc.Load(H ttpContext.Curr ent.Server.MapP ath("news.xml") ) 'loads the xml file
    loNode2 = loXMLDoc.Select SingleNode("//rss/channel/item/title") 'path to node that's changed
    loNode2.InnerTe xt = txtTitle.Text 'text box that users enter the information to add to the xml file
    loNode = loXMLDoc.Select SingleNode("//rss/channel/item/description") 'path to node that's changed
    loNode.InnerTex t = txtDescription. Text 'text box that users enter the information to add to the xml file
    loNode3 = loXMLDoc.Select SingleNode("//rss/channel/item/link") 'path to node that's changed
    loNode3.InnerTe xt = txtLink.Text 'text box that users enter the information to add to the xml file

    loXMLDoc.Save(H ttpContext.Curr ent.Server.MapP ath("news.xml") )
    loNode = Nothing
    loNode2 = Nothing
    loNode3 = Nothing
    loXMLDoc = Nothing

    Response.Redire ct("http://theredirectpage goeshere")
    End Sub

    So, I'm trying to add more title, description, link but it's not working out at planned. The item has an id but it doesn't have to as I'm checked modified it and viewed it on the web and it just displays them in the order of the document. Any help would be appreciated. I know this is probably a simple fix like modifying the loXMLDoc.Save to something else but I just can't put my finger on it.

    Thanks!
  • Webdesigner29
    New Member
    • Apr 2008
    • 2

    #2
    Bump--does anyone have an aswer to this?

    Comment

    Working...