Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you write linq-to-xml for data between XML elements?
    primarykey
    data
    text
    <p>I am trying to parse some XML that looks similar to this:</p> <pre><code>&lt;document&gt; &lt;headings&gt; Important heading stuff. &lt;/headings&gt; &lt;startGroup group="1" /&gt; &lt;startItem value="1" /&gt;Item one stuff&lt;endItem /&gt; &lt;blockofdata&gt; &lt;startItem value="2" /&gt;Item two stuff&lt;endItem /&gt; &lt;startItem value="3" /&gt;Item three stuff&lt;endItem /&gt; &lt;/blockofdata&gt; &lt;startItem value="4" /&gt;Item four stuff&lt;endItem /&gt; &lt;endGroup /&gt; &lt;startGroup group="2" /&gt; &lt;startItem value="1" /&gt;Item one stuff&lt;endItem /&gt; &lt;startItem value="2" /&gt;Item two stuff&lt;endItem /&gt; &lt;startItem value="3" /&gt;Item three stuff&lt;endItem /&gt; &lt;endGroup /&gt; &lt;/document&gt; </code></pre> <p>I cannot figure out a linq-to-xml statement to get what I want. I need to flatten the structure. So assuming the above XML, I would like to get a list of this POCO:</p> <pre><code>class Items { public int GroupNumber {get;set;} // group property of startGroup public int ItemNumber {get;set;} // value property of startItem public string ItemText {get;set;} // data between i } </code></pre> <p>How do you write a linq-to-xml statement that would pull the data between the attributes into the above item while grabing the data from between startGroup/endGroup and the data between startItem/endItem? I have burned up several hours on this and am about to just switch to using a XML stream reader and parsing it the old fashioned way.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload