Simple Filter Question
-
I am venturing into the .NET XML world and have already run into a problem. I have some very simple (I think) XML that defines several loan rate values, with attributes indicating the min and max amount for the loan:
10.25 14.75 5.25 9.75
So, a loan for $2500.00 should have a margin of 10.25/floor of 14.75, while a loan of $7500.00 should have a margin of 5.25/floor of 9.75. I want to access these values in my C# code to calculate the rate/payment, but am stuck.XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Server.MapPath(@"~\App_Data\LoanInformation.xml")); string xPath = string.Format("//LoanRates/Loan[@MinValue >= '{0:000000.00}' and @MaxValue <= '{0:000000.00}']", plcdata.LoanAmount); XmlNode node = xmlDoc.SelectSingleNode(xPath);
node seems to always be null, unless I remove the 'and @Max ..' clause. I added the leading zero's in case text vs. number comparison was causing a problem. Any pointers would be greatly appreciated. --G -- modified to "ignore HTML tags" -
I am venturing into the .NET XML world and have already run into a problem. I have some very simple (I think) XML that defines several loan rate values, with attributes indicating the min and max amount for the loan:
10.25 14.75 5.25 9.75
So, a loan for $2500.00 should have a margin of 10.25/floor of 14.75, while a loan of $7500.00 should have a margin of 5.25/floor of 9.75. I want to access these values in my C# code to calculate the rate/payment, but am stuck.XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Server.MapPath(@"~\App_Data\LoanInformation.xml")); string xPath = string.Format("//LoanRates/Loan[@MinValue >= '{0:000000.00}' and @MaxValue <= '{0:000000.00}']", plcdata.LoanAmount); XmlNode node = xmlDoc.SelectSingleNode(xPath);
node seems to always be null, unless I remove the 'and @Max ..' clause. I added the leading zero's in case text vs. number comparison was causing a problem. Any pointers would be greatly appreciated. --G -- modified to "ignore HTML tags"Your XPath query is incorrect. Your code should read:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath(@"~\App_Data\LoanInformation.xml"));
string xPath = string.Format("//LoanRates/Loan[@MinValue <= '{0:000000.00}' and @MaxValue >= '{0:000000.00}']", plcdata.LoanAmount);
XmlNode node = xmlDoc.SelectSingleNode(xPath);Paul Marfleet
-
Your XPath query is incorrect. Your code should read:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath(@"~\App_Data\LoanInformation.xml"));
string xPath = string.Format("//LoanRates/Loan[@MinValue <= '{0:000000.00}' and @MaxValue >= '{0:000000.00}']", plcdata.LoanAmount);
XmlNode node = xmlDoc.SelectSingleNode(xPath);Paul Marfleet
Duh! I've been trying various combinations, *assuming* the problem was XML (and my lack thereof) related. Stupid logic! Thanks. --G