markknowsley
Programmer
I have some XML in the following format:
I've loaded the XML, created an XMLNodeList and then iterated through, i.e:
This works fine and gets rid of the two nodes. However, I want to delete XML based on the value of the AuthStatus field - if this is set to 'Approved' then I want to delete the node.
But if I change the XPath to @authstatus='Approved' I get an 'Object Reference not set to an instance of an Object' error. Can someone tell me why this is?
Mark.
Code:
<employee ID="000001" Initials="G" Surname="RUSEDSKI ">
<summary batchnumber="00841" batchitem="01" claimmonth="1" claimyear="2007" Miles="154" amount="27.72" AuthStatus="Rejected" vmodifiedby="" vnotes=""/>
</employee>
<employee ID="000014" Initials="T" Surname="HENMAN ">
<summary batchnumber="00841" batchitem="02" claimmonth="1" claimyear="2007" Miles="24" amount="10.18" AuthStatus="Rejected" vmodifiedby="" vnotes=""/>
</employee>
I've loaded the XML, created an XMLNodeList and then iterated through, i.e:
Code:
foreach (XmlNode node in nodeList)
{
node.RemoveChild(node.SelectSingleNode("//summary[@batchnumber='00841']);
}
This works fine and gets rid of the two nodes. However, I want to delete XML based on the value of the AuthStatus field - if this is set to 'Approved' then I want to delete the node.
But if I change the XPath to @authstatus='Approved' I get an 'Object Reference not set to an instance of an Object' error. Can someone tell me why this is?
Mark.