c# - Read each node in IEnumerable<XElement> using XMlReader -
i have ienumerable<xelement> thetestcasenodes
has following kind of xelements
<testcase> <main> <test_step type ="action"> <name>goto</name> <description>xxxxxxxxx</description> </test_step> <test_step type ="check"> <name>click</name> <description>xxxxxxxxx</description> </test_step> </main> </testcase> <testcase> <main> <test_step type ="action"> <name>goto</name> <description>xxxxxxxxx</description> </test_step> <test_step type ="check"> <name>type</name> <description>xxxxxxxxx</description> </test_step> </main> </testcase>
basically testcase , want execute them in order. so, want read each node in ienumerable using xmlreader.
please how proceed!!
i understood need use "using" not sure how proceed.
public void executetestcase(ienumerable<xelement> thetestcasenodes) { using (xmlreader anodereader = xmlreader.readsubtree()) { } }
use xelement.createreader
instantiating xmlreader
element.
public void executetestcase(ienumerable<xelement> thetestcasenodes) { foreach(var node in thetestcasenodes) { using (var reader = node.createreader()) { // use xmlreader testing } } }
if main purpose of xmlreader
reading elements in correct order looping through elements execute them in same order appear in xml
foreach(var teststep in thetestcasenodes.elements("test_step")) { // execute step }
if don't want rely on order of xml can access correct step type
attribute
foreach(var teststep in thetestcasenodes.elements("main")) { var action = teststep.elements("test_step") .first(step => step.attribute("type") == "action"); var check = teststep.elements("test_step") .first(step => step.attribute("type") == "action"); // execute action // execute check }
Comments
Post a Comment