Multiple XML file reader and print as feed in HTML using jquery
Multiple XML file reader and print as feed in HTML using jquery
Hello everybody I need to add an XML feed banner to a simple HTML website. I've got a variable number of XML files that contain some data placed in a directory in the root of this simple HTML website and named in random. I need to recursively print the XML tag "titolo" from those XML files in a HTML <div class="news">
meabe should be done with jQuery.
<div class="news">
I need something like in this link http://jsfiddle.net/mVtCD/ but i need to read many random named files in my directory.
This is the code of one of this random XML files:
<?xml version="1.0" encoding="UTF-8"?><docfieg81>
<metadati>
<categoria>economia</categoria>
<ambitoregionale>nazionale</ambitoregionale>
<priorita>7</priorita>
</metadati>
<titolo>Inflazione +1,4%, stangata per famiglie</titolo>
<testo>
<p>Roma, 28 giu. (AdnKronos) - Il tasso di inflazione accelera all'1,4% a giugno.</p>
</testo>
<datanotizia>2018-06-28</datanotizia>
<oranotizia>14:42</oranotizia>
</docfieg81>
I've tried somenthing like this code:
$(document).ready(function () {
$.ajax({
url: 'http://localhost/klausdavi/news/',
type: 'GET',
dataType: "xml"
}).done(function(xml) {
$.each($("item", xml), function(i, e) {
var itemTitle = ($(e).find("titolo"));
var blogTitle = "<h4>" + itemTitle.text() + "</h4>";
$("news").append(blogTitle);
});
});
});
I've search for many tutorials around the internet but no one was good for me... Many thanks...
I've found a solutio using this code below but I need at least to load a XML file into a JS variable and don't know why I'm getting error 404 not found.
$(document).ready(function () {
//var testing;
//Sample XML
var xml = "<?xml version='1.0' encoding='UTF-8'?><docfieg81><metadati><categoria>cronaca</categoria><ambitoregionale>nazionale</ambitoregionale><priorita>7</priorita></metadati><titolo>Manageritalia, dirigenti ccnl terziario cresciuti più del mercato</titolo><testo><p>Milano, 28 giu. (Labitalia) - La crisi non ha toccato i lavoratori interessati dal contratto dirigenti terziario, gestito da Manageritalia </p></testo><datanotizia>2018-06-28</datanotizia><oranotizia>12:44</oranotizia></docfieg81>";
var xml;
//Parse the givn XML
var xmlDoc = $.parseXML( xml );
var $xml = $(xmlDoc);
// Find Person Tag
var $person = $xml.find("docfieg81");
$person.each(function(){
var titolo = $(this).find('titolo').text(),
datanotizia = $(this).find('datanotizia').text();
$("#js-news" ).append('<li class="news-item">' +titolo+ ' - ' +datanotizia+ '</li>');
});
});
is a simple HTML web page with javascript / jquery no other frameworks
– Darius Pum
Jun 29 at 10:15
@mortb i've posted my actual jquery code, thanks for your support
– Darius Pum
Jun 29 at 10:38
Well, as I see it you will need some back end handler. There is no proper way for the browser to know what files that reside on the server. If that was possible it would be a security risk. The risk is that you would be able to write javascript code that connected to various servers and asked for a list of their files. Sure, if you use a browser and navigate to a directory on your server that has directory browsing allowed you will be served a list of files, but having directory browsing allowed is not really a good idea from a security perspective.
– mortb
Jun 29 at 11:59
I dont need any back end handler i just need a recursive jquery code that import recursively all the XML files inside the function and print the
titolo
XML tag appending it in the HTML <div>
– Darius Pum
Jun 29 at 12:38
titolo
<div>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Your post provides too little information. What is your backend environment (microsoft asp / mvc / java etc)? What have you tried? stackoverflow.com/help/how-to-ask
– mortb
Jun 29 at 10:12