Add a check
if (ownerID != null)
to before the last line. Most probably your XPath is not correct (or there simply isn't any matching element).
Domanda
I am trying to change an existing attribute value of an XML Node that has child nodes. I am getting an exception when trying to do this.
string specificOwnerPath = "Owners/Owner[@id='" + startingOwnerName + startingOwnerZipCode + "']";
XmlNode ownerID = doc.SelectSingleNode(specificOwnerPath);
ownerID.Attributes["id"].Value = ownerNameTextBox.Text + ownerZipCodeTextBox.Text;
The exception I am getting says 'Object reference not set to the instance of an object and is occurring at the final line of code shown above. Does anyone have any suggestions on what I am doing wrong?
Soluzione
Add a check
if (ownerID != null)
to before the last line. Most probably your XPath is not correct (or there simply isn't any matching element).
Altri suggerimenti
if (ownerID != null)
Xpath is not correct in last line