I have an XML doc used as database. It includes many <product> elements, each with children like <price>, <name>, <quantity>... Example:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<product code="AS542EG2542">
<title>Best product in the market</title>
<category>something 1</category>
<price>10.99</price>
</product>
<product code="AS542EG2542">
<title>Second best product in the market</title>
<category>something 2</category>
<price>58.99</price>
</product>
<product code="AS542EG2542">
<title>Third best product in the market</title>
<category>something 2</category>
<price>24.99</price>
</product>
</catalog>
Then, in a website, I'm using AJAX to call for it, and then retrieve information and insert it in the DOM:
// Get the XML document
var request = $.ajax({
url: "http://www.example.com/resources/database.xml",
dataType: 'xml',
cache: 'false',
method: 'GET',
async: 'true'
});
// After AJAX has been completed, run the following function
request.done(function() {
testingFunction(request);
});
// The function that extracts data from XML and inserts it into the DOM
function testingFunction(xml) {
var xmlDoc = xml.responseXML,
xml = $( xmlDoc ),
// For each <product> elementt there is in the XML:
productsList = xml.find("product").each(function () {
// get child <title> of each <product>
var titleValue = $( this ).find("title").text();
// get child <price> of each <product>
var priceValue = $( this ).find("price").text();
// create a <li><div> titleValue </div><div> priceValue </div></li>
$("ul").append('<li><div class="iss-title">' + titleValue + '</div><div class="iss-price">' + priceValue + '</div</li>');
});
}
(I'm relatively new to programming)
Is this good practice? I've read XML is for organized data, not for storing them as database. Also I've read about SQL databases provided by e.g. MySQL, PostgreSQL, etc and that I can get data from their database tables using PHP to inject it into the DOM.
Would in my case be better to use a SQL database like MySQL? Following these criteria:
- Is good practice. E.g. as I said XML is for data used to be transported in a readable way for programs.
- Google bot can read/crawl the dynamically generated content from the SQL database. I've read about XML and it looks like Google won't crawl AJAX.
requesttotestingFunctionat.done()callback? googlebot crawls everything it can.