Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Edit an XML file (Vb.NET)

  • 01-10-2008 12:48PM
    #1
    Registered Users, Registered Users 2 Posts: 8,566 ✭✭✭


    I have the following XML file which I need to edit
    - <ImportSession DeleteBatchOnError="1">
    - <Batches>
    - <Batch BatchClassName="EmailOutput">
    - <Documents>
    - <Document RequestID="22">
    - <IndexFields>
      <IndexField Name="EmailFrom" Value="hello" /> 
      <IndexField Name="EmailFromAddress" Value="he.llo@hotmail.com" /> 
      <IndexField Name="EmailTo" Value="hello@hotmail.com" /> 
      <IndexField Name="EmailSubject" Value="Test Thursday" /> 
      <IndexField Name="EmailCC" Value="" /> 
      <IndexField Name="EmailDateTime" Value="9/25/2008 2:17:45 PM" /> 
      <IndexField Name="MailboxName" Value="mailbox" /> 
      <IndexField Name="OBJECT_CLASS" Value="Email" /> 
      <IndexField Name="Policy_No" Value="012344" /> 
      <IndexField Name="Claim_No" Value="999999999" /> 
      <IndexField Name="Broker_No" Value="876543" /> 
      </IndexFields>
      </Document>
      </Documents>
      </Batch>
      </Batches>
      </ImportSession>
    
    

    I can retrieve the values using the following
    Dim xmlObj As New Xml.XmlDocument
            Dim m_node As Xml.XmlNode
            Dim m_nodelist As XmlNodeList
            Dim policyNo as string
    
            xmlObj.Load(_file)
    
            m_nodelist = xmlObj.SelectNodes("/ImportSession/Batches/Batch/Documents/Document/IndexFields/IndexField[@Name='Policy_No']")
    
            'Load the document 
            Try
                m_nodelist = xmlObj.SelectNodes("/ImportSession/Batches/Batch/Documents/Document/IndexFields/IndexField[@Name='Policy_No']")
                For Each m_node In m_nodelist
                   policyNo = m_node.Attributes.GetNamedItem("Value").Value = "01PMV0123456"
                Next
    
    

    I need to edit the Policy_No element. Can some direct me in the right direction please.

    I tried doing setnameditem but looking for xml object
    Thanks in advance


Advertisement