Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting XML nodes

Status
Not open for further replies.

markknowsley

Programmer
Aug 30, 2005
152
GB
I have some XML in the following format:

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.
 
XML is case sensitive and I noticed AuthStatus in the XML and your XPath authstatus do not match - hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top