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         }     } } 

xnode.createreader method ()

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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -