Hi, I'm trying to update an XML file, but only a specific row.
For instance in the xml sample below, there are four records, each with their own ID.
I want to be able to update the record, where the ID = 4
This is the code sample I've been working with, but this only updates the first instance of EJstatus.Code:<?xml version="1.0" standalone="yes"?> <DocumentElement> <returnset> <ID>3</ID> <EJStatus /> </returnset> <returnset> <ID>4</ID> <EJStatus /> </returnset> <returnset> <ID>5</ID> <EJStatus /> </returnset> <returnset> <ID>6</ID> <EJStatus /> </returnset> </DocumentElement>
I also tried looping each attribute to find the correct record for updating, but this never worked either.Code:Public Sub SaveXMLFile() 'Dim xmlDoc As New XmlDataDocumentxmlDoc.Load(dirPath & "jobs3.xml") Dim xmlDoc As New XmlDataDocument() xmlDoc.Load(dirPath & "jobs3.xml") Dim node As XmlNode = xmlDoc.SelectSingleNode("//DocumentElement/returnset/ID[. ='4']") Dim nodev As XmlNode = xmlDoc.SelectSingleNode("//DocumentElement/returnset/EJStatus") If node IsNot Nothing Then nodev.InnerText = "done" End If 'For Each Attribute As XmlAttribute In xmlDoc.DocumentElement.Attributes ' If Attribute("ID").Value = 4 Then ' Attribute("EJStatus").InnerText = "read" ' End If ' Next xmlDoc.Save(dirPath & "jobs3.xml") End Sub
Any help on how to update the correct record would be much appreciated.
Many thanks
Dave




Reply With Quote