My XML file is quite extensive, divided into various sections. Each page loads content from the XML based on a category node (list_node). Currently, I am extracting content by directly referencing the nodes, but it becomes cumbersome to add a line for each node.
Is there a way to parse the XML, store the nodes in an array, and then assign a new variable to represent the node name and its contents? This snippet shows my current configuration:
<media_item>
<title>temporary title</title>
<key>652843722</key>
<path>/states/CA</path>
<filename>climate-pollution-harmful.html</filename>
<link>http://a-url-goes-here.com</link>
<blank>yes</blank>
<author/>
<date>August 15, 2015</date>
</media_item>
(Please note that the actual XML contains more nodes than shown above, with different categories indicated by the "list_node" call earlier in my code)
$.ajax({
type: "GET",
url: "http://url-of/file.xml,
dataType: "xml",
success: function(xml){
$(xml).find(list_node).each(function(i){
var title = $(this).find('title').text();
var url = $(this).find('link').text();
var date = $(this).find('date').text();
var author = $(this).find('author').text();
var org = $(this).find('org').text();
Instead of manually defining variables like "var title = $(this).find('title').text();" for every node, I am looking for a way to automate this process.