Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery: parse XML with inconsistent row data into a table
    primarykey
    data
    text
    <p>This is probably a very rookie question but i am stumped. </p> <p>I have the following code which is parsing an XML file and putting each element into a table. My problem is that there is not always nine elements in each row and the names of each element changes between XML files. Is there any way to create a loop that runs through each row (without knowing the element name (<code>col0</code>, <code>col1</code>, etc) ) and puts it into a table? </p> <p>The XML goes like this:</p> <pre><code>&lt;row&gt; &lt;Col0&gt;titles&lt;/Col0&gt; &lt;Col1&gt;more titles&lt;/Col1&gt; &lt;Col2&gt;title&lt;/Col2&gt; &lt;Col3&gt;name&lt;/Col3&gt; &lt;Col4&gt;another name&lt;/Col4&gt; &lt;Col5&gt;different name&lt;/Col5&gt; &lt;Col6&gt;&lt;/Col6&gt; &lt;Col7&gt;&lt;/Col7&gt; &lt;Col8&gt;&lt;/Col8&gt; &lt;/row&gt; &lt;row&gt; &lt;Col0&gt;5:58&lt;/Col0&gt; &lt;Col1&gt;-&lt;/Col1&gt; &lt;Col2&gt;6:08&lt;/Col2&gt; &lt;Col3&gt;6:11&lt;/Col3&gt; &lt;Col4&gt;6:15&lt;/Col4&gt; &lt;Col5&gt;6:19&lt;/Col5&gt; &lt;Col6&gt;&lt;/Col6&gt; &lt;Col7&gt;&lt;/Col7&gt; &lt;Col8&gt;&lt;/Col8&gt; &lt;/row&gt; </code></pre> <p>etc....</p> <p>Here is my code:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { $.get('newlayout.xml', function(d){ $('.tabl').append('&lt;table&gt;'); $(d).find('row').each(function(){ var $row = $(this); var col01 = $row.find('Col0').text(); var col02 = $row.find('Col1').text(); var col03 = $row.find('Col2').text(); var col04 = $row.find('Col3').text(); var col05 = $row.find('Col4').text(); var col06 = $row.find('Col5').text(); var col07 = $row.find('Col6').text(); var col08 = $row.find('Col7').text(); var col09 = $row.find('Col8').text(); html = '&lt;tr&gt;' html += '&lt;td style="width:80px"&gt; ' + col01 + '&lt;/td&gt;'; html += '&lt;td style="width:80px"&gt; ' + col02 + '&lt;/td&gt;' ; html += '&lt;td style="width:80px"&gt; ' + col03 + '&lt;/td&gt;' ; html += '&lt;td style="width:80px"&gt; ' + col04 + '&lt;/td&gt;' ; html += '&lt;td style="width:80px"&gt; ' + col05 + '&lt;/td&gt;' ; html += '&lt;td style="width:80px"&gt; ' + col06 + '&lt;/td&gt;' ; html += '&lt;td style="width:80px"&gt; ' + col07 + '&lt;/td&gt;' ; html += '&lt;td style="width:80px"&gt; ' + col08 + '&lt;/td&gt;' ; html += '&lt;td style="width:80px"&gt; ' + col09 + '&lt;/td&gt;' ; html += '&lt;/tr&gt;'; $('.tabl').append($(html)); }); }); }); </code></pre> <p>Thanks in advance,<br> Tom</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