Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Update XML textNode ASP.Net/VB.Net

    Does anyone know a way and/or a tutorial that shows how to update a XML textNode value?

    ex:

    XMLDoc
    <ParentNode>
    <ChildNode1>
    <ValueNode1>SomeData</ValueNode1>
    <ValueNode2>SomeMoreData</ValueNode2>
    <ValueNode3>EvenMoreData</ValueNode3>
    </ChildNode1>
    </ParentNode>

    I would like to know how to change,

    <ValueNode2>SomeMoreData</ValueNode2>

    To

    <ValueNode2>UpdatedMoreData</ValueNode2>

    language VB.Net/Asp.Net

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    New York, USA
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Before anything else, you might want to bookmark this...

    http://samples.gotdotnet.com/QuickSt...viewofxml.aspx

    Like most things in .NET, there are multiple ways of handling tasks, depending on your needs. Here's a simple snippet that opens an XML document, updates a node, and saves the document.

    Code:
    Imports System.Xml
    
    '.....
    
    Dim loXMLDoc As XmlDocument = New XmlDocument
    Dim loNode As XmlNode
    
    loXMLDoc.Load("C:\Path\To\Document.xml")
    loNode = loXMLDoc.SelectSingleNode("//ParentNode/ChildNode1/ValueNode2")
    loNode.InnerText = "UpdatedMoreData"
    loXMLDoc.Save("C:\Path\To\Document.xml")
    
    loNode = Nothing
    loXMLDoc = Nothing

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Many Thanks!

    I've been looking around for days to find a SIMPLE sample - anbd this is just it - I can use this to read a value then update it - SIMPLE!

    CHEERS!

  • #4
    New Coder
    Join Date
    Aug 2008
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried doing this with a function and failed... what am I doing wrong?

  • #5
    Regular Coder
    Join Date
    Jun 2008
    Location
    SE Wisconsin, US
    Posts
    222
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Code that is very similar to this has worked for me in the past. Using SelectSingleNode is probably the most efficient way to do this.
    Milwaukee Web Designer and SEO Milwaukee Firm specializing in ASP.Net, C#, VB.Net, SQL Server and Access.


  •  

    Posting Permissions

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