I am trying to create a XML file to store data which will be loaded onto my site (which will later become an app)
I understand how to load the frist Categories
sections using .find()
but not the rest (contained withing Categories and so forth) I also get the sneaking suspicion the XML could be simpler like the name <category name="name">
or something also is it possible to make a template for each page (with jQuery) to load the data automatically? have been looking at handlebars but does seem necessary.
I am very new to JS and XMl as you can probably tell, I hope I have given enough info and made myself clear, any help or insight would be great. Reading below should help make thinks clear.
JS to load and show Categories:
$(document).ready(function () {
$.ajax({
type: "GET",
url: "data.xml",
dataType: "xml",
success: xmlParser
});
});
function xmlParser(xml) {
$('#load').fadeOut();
$(xml).find("category").each(function () {
$(".categories").append('<dt>'
+ $(this).find("category-name").text()
+ '</dt><dd>'
+ $(this).find("category-description").text()
+ '</dd>');
// $(".category").fadeIn(1000);
});
}
html:
<dl class="categories margins-removed">
<!-- Categories show here -->
</dl>
<div class="main">
<div align="center" class="loader">
<img src="loader.gif" id="load" align="absmiddle"/>
</div>
</div>
the site will show the Categories first > genres for selected category > list items for selected genre > List item from selected genre (each is a new page)
My Current XML (there are more Categories but there's no point showing the code here.)
<category>
<category-name>category one</category-name>
<category-description>what is category one about</category-description>
<genres>
<genre> <!-- start of genre -->
<name>genre one</name>
<description>what is genre one about</description>
<list>
<item>
<img></img>
<name></name>
<description></description>
</item>
<item>
<img></img>
<name></name>
<description></description>
</item>
<item>
<img></img>
<name></name>
<description></description>
</item>
</list>
</genre>
<genre> <!-- start of genre -->
<name>genre two</name>
<description>what is genre two about</description>
<list>
<item>
<img></img>
<name></name>
<description></description>
</item>
<item>
<img></img>
<name></name>
<description></description>
</item>
<item>
<img></img>
<name></name>
<description></description>
</item>
</list>
</genre>
</genres>
</category>