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
Updated 28-Feb-18 0:05am
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

1 solution

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

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

    XmlDocument model = new XmlDocument();


    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 !");
        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);

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