Results 1 to 2 of 2

Thread: Write to XML node

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Cairo, Egypt
    Posts
    126

    Angry Write to XML node

    Hi All;
    I have a XML file like the old ini and I want to write to a specific node in it. I have the Microsoft sample (101 VB.NET Samples), it has a project with write and read XML files. Here it is the sample code from it.

    VB Code:
    1. Private Sub ModifyElementValue()
    2.     ' Shows how to modify an element's text value
    3.     Dim xDoc As New XmlDocument()
    4.  
    5.     xDoc.Load(mstrModifyFile)
    6.  
    7.     Me.txtXMLDisplay.Text = xDoc.OuterXml
    8.  
    9.     Dim xNode As XmlNode
    10.     Dim xElem As XmlElement
    11.  
    12.     Dim xElmntFamily As XmlElement
    13.     xNode = xDoc.SelectSingleNode("//Person")
    14.  
    15.     If Not (xNode Is Nothing) Then
    16.         xElem = CType(xNode, XmlElement)
    17.  
    18.         ' Change "Gerald L. Smith" to "Jerry Smith"
    19.         xElem.InnerText = "Jerry Smith"
    20.  
    21.         Me.txtXMLEdits.Text = xDoc.OuterXml
    22.     Else
    23.         Me.txtXMLEdits.Text = String.Format("Family Node was not found. Please try the '{0}' option first.", CMD_CREATE_XML)
    24.     End If
    25. End Sub

    I run it and it didn't change the XML element with the new value, I have also another code and it dosen't work too.

    VB Code:
    1. Dim xmlList As XmlNodeList
    2.     Dim xmlDoc As New XmlDocument
    3.  
    4.     Try
    5.         xmlDoc.Load(XMLFileName)
    6.  
    7.         xmlList = xmlDoc.GetElementsByTagName(NodeName)
    8.  
    9.         If xmlList.Count > 0 Then
    10.             xmlList(0).InnerText = ValueString
    11.         End If
    12.     Catch ex As XmlException
    13.     End Try

    Within the program when runing and debuging the value changed but in the real after I close the application and return to run it again the old value of the element still as it not changed

  2. #2
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Re: Write to XML node

    it appears you are not saving the xml file..?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

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