Note that there are some explanatory texts on larger screens.

plurals
  1. POconvert xml to object with jquery
    primarykey
    data
    text
    <p>I have a xml file like this: (this is dynamically create xml file the categories are not static)</p> <pre><code>&lt;data&gt; &lt;step id="1"&gt; &lt;category id="js"&gt;&lt;/category&gt; &lt;category id="css"&gt;&lt;/category&gt; &lt;category id="xml"&gt;&lt;/category&gt; &lt;/step&gt; &lt;step id="2"&gt; &lt;category id="js"&gt;&lt;/category&gt; &lt;category id="css"&gt;&lt;/category&gt; &lt;category id="xml"&gt;&lt;/category&gt; &lt;category id="php"&gt;&lt;/category&gt; &lt;category id="html"&gt;&lt;/category&gt; &lt;/step&gt; &lt;step id="3"&gt; &lt;category id="xml"&gt;&lt;/category&gt; &lt;category id="php"&gt;&lt;/category&gt; &lt;category id="html"&gt;&lt;/category&gt; &lt;/step&gt; &lt;/data&gt; </code></pre> <p>I want convert the xml file in a javascript object i do it with jquery </p> <pre><code>$.get('data.xml', function(xml){ var oXML = $(xml).find('data'), data = {}; oXML.each(function(){ var stepID = jQuery(this).attr('id'); data[stepID] = {}; jQuery(this).each(function(){ var categoryID = jQuery(this).attr('id') data[stepID][categoryID] = 'is available'; }); }); }); </code></pre> <p>the result looks like this</p> <pre><code>obj = { 1: { js: 'is available', css: 'is available', xml: 'is available' }, 2: { js: 'is available', css: 'is available', xml: 'is available', php: 'is available', html: 'is available' }, 3: { xml: 'is available', php: 'is available', html: 'is available' } } </code></pre> <p>but i want have all categories in all steps. do you have a idea how i can do it? I want a result object like this</p> <pre><code>obj = { 1: { js: 'is available', css: 'is available', xml: 'is available', php: 'is not available', html: 'is not available' }, 2: { js: 'is available', css: 'is available', xml: 'is available', php: 'is available', html: 'is available' }, 3: { js: 'is not available', css: 'is not available', xml: 'is available', php: 'is available', html: 'is available' } } </code></pre>
    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.
    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