Hi,
Im trying to search through an XML file. When it finds the record it needs it then updates a specific field in that record. I have made it find the specified record but do not know how to update it and write it back to file. I am new to XML coding. Any help would be most appreciated.
Dim xpathDoc As XPathDocument
Dim xmlNav As XPathNavigator
Dim xmlNI As XPathNodeIterator
Dim filePath As New OpenFileDialog
filePath.ShowDialog()
xpathDoc = New XPathDocument(filePath.FileName)
xmlNav = xpathDoc.CreateNavigator()
xmlNI = xmlNav.Select("/Message/Pupils/PupilCode")
While (xmlNI.MoveNext())
System.Console.WriteLine(xmlNI.Current.Name + " : " + xmlNI.Current.Value)
If (xmlNI.Current.Value) = "A123981456002" Then
'ONCE ITS FOUND THE RECORD - DISPLAY A MESSAGE
'SELECT THE DIFFERENT FIELD WITHIN THE RECORD
MsgBox("Found")
xmlNav.Select("/Message/Pupils/PupilAge")
'THIS IS WHERE IT NEEDS TO UPDATE IT. NO IDEA HOW TO DO THIS BIT
End If
End While
This may be the wrong way to do it - I'm not sure. I just need it to search for a specific pupil ID and update their age with a specified value. After that it has to write the entire XML file to a new file.
Many thanks.
Chris
Im trying to search through an XML file. When it finds the record it needs it then updates a specific field in that record. I have made it find the specified record but do not know how to update it and write it back to file. I am new to XML coding. Any help would be most appreciated.
Dim xpathDoc As XPathDocument
Dim xmlNav As XPathNavigator
Dim xmlNI As XPathNodeIterator
Dim filePath As New OpenFileDialog
filePath.ShowDialog()
xpathDoc = New XPathDocument(filePath.FileName)
xmlNav = xpathDoc.CreateNavigator()
xmlNI = xmlNav.Select("/Message/Pupils/PupilCode")
While (xmlNI.MoveNext())
System.Console.WriteLine(xmlNI.Current.Name + " : " + xmlNI.Current.Value)
If (xmlNI.Current.Value) = "A123981456002" Then
'ONCE ITS FOUND THE RECORD - DISPLAY A MESSAGE
'SELECT THE DIFFERENT FIELD WITHIN THE RECORD
MsgBox("Found")
xmlNav.Select("/Message/Pupils/PupilAge")
'THIS IS WHERE IT NEEDS TO UPDATE IT. NO IDEA HOW TO DO THIS BIT
End If
End While
This may be the wrong way to do it - I'm not sure. I just need it to search for a specific pupil ID and update their age with a specified value. After that it has to write the entire XML file to a new file.
Many thanks.
Chris