Quote:
Originally Posted by surya926
Hello!
I want to generate dynamicaly xpath in c#.net code from xml file which is having multiple child elements under parent element.The purpose of generating xpath is uses for calculation.The following is the code is hard coded mentioning particular nodes for calculating commission.
public void CalculateCommissionAmount(string policyXML, string rate)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(policyXML);
XmlElement root = xmldoc.DocumentElement;
if (Convert.ToDouble(rate) < -5)
{
MessageBox.Show("Invalid Rate - Rate cannot be less than -5%.");
}
else if (Convert.ToDouble(rate) > 100)
{
MessageBox.Show("Invalid Rate - Rate cannot be more than 100%.");
}
else
{
try
{
XmlNodeList xmlnode = xmldoc.GetElementsByTagName("PersonalAutoVehicle") ;
for(int i=0; i<xmlnode.Count; i++)
{
cmmAmount = Convert.ToDouble(rate)/100 * Convert.ToDouble(xmlnode[i].SelectSingleNode("PersonalAutoVehicleLiabilityCov erage/BasePremium").InnerText);
xmlnode[i].SelectSingleNode("PersonalAutoVehicleLiabilityCov erage/FFICCombinedSingleLimitCommissionAmount").InnerTex t = Convert.ToString(cmmAmount);
cmmTotalAmount += cmmAmount;
}
XmlNode node = root.SelectSingleNode("Policy/PersonalAuto/CommissionRate");
node.InnerText = rate;
XmlNode amtNode = root.SelectSingleNode("Policy/PersonalAuto/FFICTotalCommissionAmountForVehicleLiabilityCovera ge");
amtNode.InnerText = Convert.ToString(cmmTotalAmount);
FileStream fsxml = new FileStream(policyXML,FileMode.Truncate,FileAccess. Write,FileShare.ReadWrite);
xmldoc.Save(fsxml);
}
catch(Exception ex)
{
WriteToEventLog(ex.Message, "CommissionCalculation", EventLogEntryType.Error, "FFICCommission");
MessageBox.Show("Error logged.");
}
}
}
i want to calculate for multiple checking multiple node,so please help me how to generate dynamicaly xpath.
thank you
Let me ask around, surya926!
Will let you know, as I do no know C# quite yet.
Please stay tuned!
Dököll