Click here to Skip to main content
15,747,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to handle MAX, NULL values in rule engine.
Suppose if my First xml element value is null and its integer, how can i compare the xml element with a non null value?

What I have tried:

i tried converting which gave me no response
Posted
Updated 28-Feb-18 0:05am
Comments
RickZeeland 28-Feb-18 5:26am    
Oops, seems my question was posted as a Solution, sorry about that !
My question was: what rule engine are we talking about here ?
Please reply by using the comment button ...
Member 13701048 28-Feb-18 5:29am    
it is a c# rule engine where you can get the values based on given formulas and inputs.
You can see it in the following link

Dotnet Simple Rule Engine[^]
Member 13701048 28-Feb-18 5:30am    
please check in the following link
https://www.codeproject.com/Tips/1001461/Dotnet-Simple-Rule-Engine

1 solution

You could do it like this:
public void ExecuteTaxRules()
{
    XmlDocument rules = new XmlDocument();

    string directory = AppDomain.CurrentDomain.BaseDirectory + @"\TaxCalculator.xml";

    rules.Load(directory);
    XmlDocument model = new XmlDocument();

    model.LoadXml(@"<Employee><GrossSalary>900001</GrossSalary>
    <HRA>50000</HRA><Tax></Tax><NetSalary>
    </NetSalary></Employee>");

    ROM rom = Compiler.Compile(rules);
    rom.AddModel("Employee", model);

    int max = 900000;
    string grossSalary = model["Employee"]["GrossSalary"].InnerText;

    int grossInt;
    int.TryParse(grossSalary, out grossInt);

    if (string.IsNullOrEmpty(grossSalary))
    {
        Console.WriteLine("Error: GrossSalary is null or empty !");
    }
    else if (grossInt > max)
    {
        Console.WriteLine("Error: GrossSalary maximum exceeded !");
    }
    else
    {
        rom.Evaluate();
        var tax = model["Employee"]["Tax"].InnerText;
        var NetSalary = model["Employee"]["NetSalary"].InnerText;
        var message = string.Format("Tax: {0} and Net take home salary :{1}", tax, NetSalary);
        Console.Write(message);
    }

    Console.Read();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900