I have a xml file like this: (this is dynamically create xml file the categories are not static)
<data>
<step id="1">
<category id="js"></category>
<category id="css"></category>
<category id="xml"></category>
</step>
<step id="2">
<category id="js"></category>
<category id="css"></category>
<category id="xml"></category>
<category id="php"></category>
<category id="html"></category>
</step>
<step id="3">
<category id="xml"></category>
<category id="php"></category>
<category id="html"></category>
</step>
</data>
I want convert the xml file in a javascript object i do it with jquery
$.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';
});
});
});
the result looks like this
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'
}
}
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
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'
}
}
collect all categories and then enumerate through data and set missing categories: