c# - Nested looping XML elements -


this xml:

<scenario>    <steps>       <step name="a">          <check name="1" />          <check name="2" />       </step>       <step name="b">          <check name="3" />       </step>    </steps> </scenario> 

i trying loop through xml elements by, each step, doing step's respective check elements. so:

foreach(step step in steps) {    foreach(check in step) {       //    } } 

it might output like:

a1 a2 b3 

the code i'm using is:

foreach (xelement step in document.descendants("step")) {    // start looping through step's checks    foreach (xelement substep in step.elements())    { 

however not looping properly. nested loop structure above doing check elements each step, instead of doing child check elements of each step. example, output of code is:

a1 a2 a3 b1 b2 b3 

how can fix loops?

your code fine. see this

foreach (xelement step in document.descendants("step")) {     // start looping through step's checks     foreach (xelement substep in step.elements())     {         console.writeline(step.attribute("name").value + ""                          + substep.attribute("name").value);     } } 

output:

a1 a2 b3 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -