Looping through XmlNodeList

R

Raul

Hi,

I have the following code, which picks up 43 different nodes from my
XML document

XmlNodeList amortNodes = amortDoc.SelectNodes("//
TValueAmortizationSchedule/AmortizationLine");

each node looks like this:

<AmortizationLineType>8</AmortizationLineType>
<Date>09/01/2006</Date>
<Loan1Amount>100000000</Loan1Amount>
<Loan2Amount></Loan2Amount>
<Loan3Amount></Loan3Amount>
<Payment1Amount></Payment1Amount>
<Payment2Amount></Payment2Amount>
<Payment3Amount></Payment3Amount>
<InterestAccrued>0</InterestAccrued>
<InterestPaid>0</InterestPaid>
<PrincipalPaid>0</PrincipalPaid>
<UnpaidInterestBalance>0</UnpaidInterestBalance>
<PrincipalBalance>100000000</PrincipalBalance>
<TotalBalance>100000000</TotalBalance>
<RateChangeRate></RateChangeRate>
<RateChangeCompounding>13</RateChangeCompounding>

Now I am trying to loop through the node list to get get the nodes
with AmortizationLineType = 8

foreach (XmlNode amortNode in amortNodes)
{
amortType = amortNode.SelectSingleNode("//AmortizationLine/
AmortizationLineType").InnerText;
if (amortType.Equals("8"))
{
count++;

...........
}
}

Now I know from my debugging, that not all 43 nodes fulfil this
criteria (ie amortType=8). However, when I run this application, the
amortType always comes back as 8, which seems to tell me it is not
picking up the value? Any ideas?

Thanks for your help.
 
G

Guest

Hi,
the xpath you are using to select the AmortizationLineType is wrong,
the expression "//AmortizationLine/AmortizationLineType" searches for the
AmortizationLineType node from the begining of the document so each time it
returns the first AmortizationLineType node, you need to change your xpath
expression to select the AmortizationLineType that is a child of the current
AmortizationLine node, so your expression must be as follows
"//AmortizationLine/AmortizationLineType"

Regards,
Mohamed Mosalem
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top