c# - Adding results to a dictionary using xelement -
private dictionary<int, double> taxdiction { set; get; } xdocument doc = xdocument.load(path); xelement xelement = xelement.load(path); var query = nm in xelement.descendants("employeefinance") (int)nm.element("emppersonal_id") == empid select new allowancepaid { taxdiction = ?? }; var resultquery = query.singleordefault(); edited selecting xml file , insert values dictionary (taxdiction). before select 2 values , insert separate list shown below:
list1 = nm.element("listoftaxableallowance").elements("amount").attributes("benlistid").select(a => (int)a).tolist(), list2 = nm.element("listoftaxableallowance").elements("amount").select(a => (double)a).tolist() however values 2 list related , insert them dictionary. values in list1 keys , values list2 values in dictionary. thought more efficient values related. hope clear things little. thank you.
edited
i tried....
taxdiction.add(nm.element("listoftaxableallowance").elements("amount").attributes("benlistid").select(a => (int)a).tolist(),nm.element("listoftaxableallowance").elements("amount").attributes("benlistid").select(a => (int)a).tolist()) however got invalid initializer member declarator
xml sample file.
<employeefinance> <emppersonal_id>494</emppersonal_id> <nonstatdedct> <deductedamt nonstatid="1037">0</deductedamt> <deductedamt nonstatid="106">5000</deductedamt> </nonstatdedct> <totaldeduction>39909.83</totaldeduction> <totaltaxableearnings>120054.27</totaltaxableearnings> <totalnontaxableearnings>29500</totalnontaxableearnings> <no_daysworked>21.667</no_daysworked> <payperiod_enddate>2014-02-28t00:00:00</payperiod_enddate> <exchange_rate>207.00</exchange_rate> <currency>gyd</currency> <date_appointment>2009-11-30t00:00:00</date_appointment> <date_employment>1994-12-01t00:00:00</date_employment> <date_termination>0001-01-01t00:00:00</date_termination> <payperiod_startdate>2014-02-01t00:00:00</payperiod_startdate> <batchnumber>3192</batchnumber> <paye_free_pay_awarded>50000</paye_free_pay_awarded> <income_tax_rateid>4</income_tax_rateid> <nis_rateid>1</nis_rateid> <daily_rate>5540.881</daily_rate> <nis_weeks_worked>0</nis_weeks_worked> <incentive /> <retro>0</retro> <listoftaxableallowance> <amount benlistid="4">0.00000</amount> <amount benlistid="0">0</amount> </listoftaxableallowance> <listoftnonaxableallowance> <amount benlistid="4">23500.00000</amount> <amount benlistid="0">0</amount> </listoftnonaxableallowance> <listoftaxablebenefits> <amount benlistid="0">0</amount> </listoftaxablebenefits> <listofnontaxablebenefits> <amount benlistid="0">0</amount> </listofnontaxablebenefits> <listoftaxableaddincome> <amount addearnid="14">0.00000</amount> </listoftaxableaddincome> <listofnontaxableaddincome> <amount addearnid="14">6000.00000</amount> </listofnontaxableaddincome> <listofnisdeductible> <amount>0</amount> </listofnisdeductible> <listofothertaxableamount> <amount>0</amount> </listofothertaxableamount> <listofpartofpension> <amount>23500.00</amount> </listofpartofpension> </employeefinance>
i think need dictionary benlistid attribute key, , amount value:
taxdiction = nm.element("listoftaxableallowance") .elements("amount") .todictionary(a => (int)a.attribute("benlistid"), => (double)a)
Comments
Post a Comment