Updating XML nodes
At this point, you should be confident with reading data from XML files. In this section, we will be looking at updating nodes. We will start by updating a single node value. As we did previously, we will need to know the specific record we wish to update. Once we have learned how to update a single node, we will learn how to update multiple nodes. Again, a loop will be needed to perform this task.
Updating a single node
From our sample XML file, we will be updating the genre for the first record. It is currently set to Computer
. We will update this to Computer – Software
. We know that the record number is 1, and we also know the node is genre
. In our XML file, this record currently looks like this:
To apply an update, a two-step process must be performed. Here, you need to make the update and then save the change back to your XML file. You'll need a string variable to save...