Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not clear what you're trying to loop over, I think one of the tags in your question was garbled. You say: "What I want to do is to loop each of the of a certain row." and I think you had a tag in there.</p> <p>Anyway, here's some examples of extracting data from the parsed xml document using jQuery. The comments show what will be alerted.</p> <p>I think part of the problem is you have the id values as siblings rather than children to the attributes. It seems like a more coherent structure might be:</p> <pre><code>&lt;rows&gt; &lt;row id="5"&gt; &lt;cell&gt;Item1&lt;/cell&gt; &lt;attrs&gt; &lt;attr id="1"&gt; &lt;type&gt;CheckBox&lt;/type&gt; &lt;values&gt; &lt;value&gt; &lt;id&gt;10&lt;/id&gt; &lt;/value&gt; &lt;value&gt; &lt;id&gt;11&lt;/id&gt; &lt;/value&gt; &lt;/values&gt; &lt;/attr&gt; &lt;attr id="2"&gt; &lt;type&gt;CheckBox&lt;/type&gt; &lt;values&gt; &lt;value&gt; &lt;id&gt;20&lt;/id&gt; &lt;/value&gt; &lt;value&gt; &lt;id&gt;21&lt;/id&gt; &lt;/value&gt; &lt;/values&gt; &lt;/attr&gt; &lt;/attrs&gt; &lt;/row&gt; &lt;/rows&gt; </code></pre> <p>But if you don't have control over the xml, please ignore that suggestion. :-)</p> <p>Okay, here are some samples of traversal to get various pieces of data:</p> <p>First let's just get "Item1"</p> <pre><code>&lt;script type="text/javascript"&gt; // Item1 $.get('sample.xml', null, function (data, textStatus) { alert( $(data).find('rows row[id=5] cell').text()); }, 'xml'); &lt;/script&gt; </code></pre> <p>Now we'll get the 1 and the 2:</p> <pre><code>&lt;script type="text/javascript"&gt; // 1 // 2 $.get('sample.xml', null, function (data, textStatus) { $(data).find('rows row[id=5] attrs attr &gt; id').each( function(){ alert($(this).text()); // 1, 2 }); }, 'xml'); &lt;/script&gt; </code></pre> <p>And lastly, let's pull out the main attr ids and tie them into the values:</p> <pre><code>&lt;script type="text/javascript"&gt; // rows row[id=5] attrs attr &gt; id 1 has inner ids of 10,11 // rows row[id=5] attrs attr &gt; id 2 has inner ids of 20,21 $.get('sample.xml', null, function (data, textStatus) { var out = '' $(data).find('rows row[id=5] attrs attr &gt; id').each( function(){ out += 'rows row[id=5] attrs attr &gt; id ' + $(this).text(); var innerIds = []; $(this).siblings('values').find('value id').each(function(){ innerIds.push($(this).text()) }); out += ' has inner Ids of ' + innerIds.join(',') + '\n'; }); alert(out); }, 'xml'); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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