0
votes

I am trying to generate an xpath query that can be executed to select a parent node when the child attribute innertext is equal to some value. The XML is below:

<order>
  <orderitem>
    <ordername>Georgina Sinclair</ordername>
    <ordernumber>408999703657</ordernumber>
    <orderpaymentmethod>cheque</orderpaymentmethod>
    <bankname>First National Bank</bankname>
    <branch>Fourways</branch>
    <amount>275.00</amount>
    <date>12/01/2012</date>
  </orderitem>
  <orderitem>
    <ordername>Zachary Whitehead</ordername>
    <ordernumber>409122372301</ordernumber>
    <orderpaymentmethod>cheque</orderpaymentmethod>
    <bankname>ABSA</bankname>
    <branch>Irene</branch>
    <amount>70.25</amount>
    <date>12/01/2012</date>
  </orderitem>
  <orderitem>
    <ordername>Toby Henderson</ordername>
    <ordernumber>401255489873</ordernumber>
    <orderpaymentmethod>cheque</orderpaymentmethod>
    <bankname>First National Bank</bankname>
    <branch>Edenvale</branch>
    <amount>181.03</amount>
    <date>12/13/2012</date>
  </orderitem>
  <orderitem>
    <ordername>Katherine Cooke</ordername>
    <ordernumber>409155874935</ordernumber>
    <orderpaymentmethod>savings</orderpaymentmethod>
    <bankname>ABSA</bankname>
    <branch>Southdowns</branch>
    <amount>975.89</amount>
    <date>01/01/2013</date>
  </orderitem>
  <orderitem>
    <ordername>Bradley James</ordername>
    <ordernumber>409254998</ordernumber>
    <orderpaymentmethod>savings</orderpaymentmethod>
    <bankname>ABSA</bankname>
    <branch>Melville</branch>
    <amount>207.74</amount>
    <date>12/09/2012</date>
  </orderitem>
  <orderitem>
    <ordername>Sophie Lane</ordername>
    <ordernumber>409771987</ordernumber>
    <orderpaymentmethod>savings</orderpaymentmethod>
    <bankname>ABSA</bankname>
    <branch>Roodepoort</branch>
    <amount>207.74</amount>
    <date>12/31/2012</date>
  </orderitem>
</order>

I want to select the orderitem element where the bank name is equal to First National Bank. Is there an xpath method to do this in c# without LINQ? I am struggling to get this type of xpath query

1
I have edited your title. Please see, "Should questions include “tags” in their titles?", where the consensus is "no, they should not".John Saunders

1 Answers

2
votes

I'm not sure if you are looking for non-LINQ C# methods, or for the actual XPath expression, so...

C#

Depending on whether you want to use XmlDocument or XDocument:

XPath

/order/orderitem[bankname='First National Bank']