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. 6 27239
Raul wrote:
I have the following code, which picks up 43 different nodes from my
XML document
XmlNodeList amortNodes = amortDoc.SelectNodes("//
TValueAmortizationSchedule/AmortizationLine");
foreach (XmlNode amortNode in amortNodes)
{
amortType = amortNode.SelectSingleNode("//AmortizationLine/
AmortizationLineType").InnerText;
You need/want a relative XPath expression here, relative to amortNode,
so use e.g.
amortType = amortNode.SelectSingleNode("AmortizationLineType") .InnerText;
If you use // at the beginning of an XPath expression then that is
always an absolute XPath selecting from the root downwards.
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
On Mar 20, 1:35 pm, Martin Honnen <mahotr...@yahoo.dewrote:
You need/want a relative XPath expression here, relative to amortNode,
so use e.g.
amortType = amortNode.SelectSingleNode("AmortizationLineType") .InnerText;
If you use // at the beginning of an XPath expression then that is
always an absolute XPath selecting from the root downwards.
OHHHHhhhhhhhhhhhh, I didnt know that! I'm still getting used to XML
and XPath so I didn't know that the // it would make a difference
Cheers!
I'm curious, I am trying to make it pick out those with
AmortizationLineType = 8 right from the XML, hence my node list would
only contain those nodes
So I try this...
amortType =
amortNode.SelectSingleNode("AmortizationLineType=' 8'").InnerText;
But I get this error
System.Xml.XPath.XPathException: The expression passed to this method
should result in a NodeSet
Abbas wrote:
I'm curious, I am trying to make it pick out those with
AmortizationLineType = 8 right from the XML, hence my node list would
only contain those nodes
So I try this...
amortType =
amortNode.SelectSingleNode("AmortizationLineType=' 8'").InnerText;
amortNode.SelectSingleNode("AmortizationLineType[. = '8']").InnerText
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
On Mar 20, 2:10 pm, Martin Honnen <mahotr...@yahoo.dewrote:
amortNode.SelectSingleNode("AmortizationLineType[. = '8']").InnerText
gives this error
System.NullReferenceException: Object reference not set to an instance
of an object.
Abbas wrote:
On Mar 20, 2:10 pm, Martin Honnen <mahotr...@yahoo.dewrote:
> amortNode.SelectSingleNode("AmortizationLineType[. = '8']").InnerText
gives this error
System.NullReferenceException: Object reference not set to an instance
of an object.
Right, as you are looping through elements that might not meet the
condition you need to break that up e.g.
XmlNode amortType = amortNode.SelectSingleNode(
"AmortizationLineType[. = '8']");
if (amortType != null) {
Console.WriteLine(amortType.InnerText);
}
else {
// no element found
}
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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>...
|
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...
|
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>
|
by: Matthew.DelVecchio |
last post by:
hello,
i am attempting to do some databinding of an XmlNodeList to a
DropDownList. id like to avoid looping thru my nodelist and hoped to do
a simple .DataSource/.DataBind technique.
for...
|
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...
|
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...
|
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?
|
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?
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
| |