c# 4.0 - XMl parsing in c# 4.0 -
i have following xml parsed
<config> <parametrictesting>y</parameterictesting> <functionaltesting>y</functionaltesting> <utilities>n</utilities> <commonapi>n</commonapi> <clientdata>n</clientdata> <datasourcetest>y<datasourcetest> <excel> <excelfilepath>myexcel1.xlsx</excelfilepath> </excel> <access> <accessdb> </accessdb> </access> <sql> <sqlconnectionstring> </sqlconnectionstring> </sql> <runnerconsole>n</runnerconsole> <schedular>n</schedular> </config>
i using xmlreader read xml since new c# don't know why code breaking after reading second tag i.e parameterictesting.
code:
string configxml = path.getfullpath("config.xml"); xmlreader xmlreader = xmlreader.create(configxml); while (xmlreader.read()) { if ((xmlreader.nodetype== xmlnodetype.element) && xmlreader.name.equals("parametrictesting")) { // todo : write code relevant parametric testing xmlreader.read(); } else if ((xmlreader.nodetype== xmlnodetype.element)&& xmlreader.name.equals("datasourcetest")) { string datasource = xmlreader.getattribute("datasourcetest"); if (datasource.equals("y")) { if (xmlreader.name.equals("excel") && (xmlreader.nodetype == xmlnodetype.element)) { string excelfile = xmlreader.getattribute("excelfilepath"); string excelpath = path.getdirectoryname(system.reflection.assembly.getexecutingassembly().location) + "\\files\\" + excelfile; objexcel.datasourcename = excelfile; objexcel.open(); } } xmlreader.read(); } xmlreader.read(); }
my code not reading element beyond parametrictesting . please help.
you open tag of "parametrictesting" in config.xml different closing tag. correct , line passes.
also, don't close tag "datasourcetest"
here fixed xml:
<config> <parametrictesting>y</parametrictesting> <functionaltesting>y</functionaltesting> <utilities>n</utilities> <commonapi>n</commonapi> <clientdata>n</clientdata> <datasourcetest>y</datasourcetest> <excel> <excelfilepath>myexcel1.xlsx</excelfilepath> </excel> <access> <accessdb> </accessdb> </access> <sql> <sqlconnectionstring> </sqlconnectionstring> </sql> <runnerconsole>n</runnerconsole> <schedular>n</schedular> </config>
Comments
Post a Comment