473,499 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looping through XmlNodeList

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.

Mar 20 '07 #1
1 2257
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

"Raul" wrote:
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.

Mar 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
46098
by: Praveen Naregal | last post by:
hello all, I have a problem. I have an XML file like below one.I want to loop through node by node and store or display the data . Can anybody give me a sample piece of c# code? Thanks &...
3
6840
by: Cheryl | last post by:
I need a sample that shows how can loop through the attributes and display the data.(.net / c#) <?xml version="1.0" encoding="UTF-8"?> <riders> <rider> <prename id=>Lance</prename>...
2
6464
by: Claire Reed | last post by:
Dear All, I am repeatedly encountering a problem whilst looping through XML Nodes and I am unsure as to what is going on and how I can get around it. I load the following XML document into an...
1
9618
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
15
3283
by: janhm | last post by:
Hello. I need to loop through a xml file finding a specific innerxml text and then ad the content to a treeview. For example. If the innerxml im searching for is "item001" then I want the...
3
5794
by: Maurice Cosgrave | last post by:
Hi, I was wondering if there was a way to move values from an array into an XmlNodeList? I have the values loaded into a string array from a previous point in the application; now I need to...
4
4598
by: SkyHook | last post by:
1. Under the topic "Select Nodes Using XPath Navigation" it says: "All XmlNodeList objects are synchronized with the underlying document, therefore if you ... modify the value of a node, that node...
1
7985
by: bigeddie | last post by:
Hi, I'm trying to get an instance off a XmlNodeList without using selectNodes(...) XmlNodeList test1 = new XmlNodeList(); (C#) but that doesn't work. What's my mistake?
4
7764
by: eggie5 | last post by:
Hi, I have an XmlNodeList and I need to reverse it. Just like Array.Reverse(), but it has to stay as an XmlNodeList. Any ideas?
6
27247
by: Raul | last post by:
Hi, I have the following code, which picks up 43 different nodes from my XML document XmlNodeList amortNodes = amortDoc.SelectNodes("// TValueAmortizationSchedule/AmortizationLine"); each...
0
7006
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.