Recently I came across an script that is supposed to load and parse external xml, however, as I'm a beginner, I presumed if I just changed the xml url, it might work, but it didn't.
What I need to do: Parse the xml so it can be displayed as HTML.
I also tried with many different external xmls, with no success. My current xml url is: http://bws.buscape.com/service/offer...Id=5889&page=1
I tried configuring the script in Js Fiddle, but it didn't work. So you can use the following site: http://www.compileonline.com/try_javascript_online.php to run the script:
What I need to do: Parse the xml so it can be displayed as HTML.
I also tried with many different external xmls, with no success. My current xml url is: http://bws.buscape.com/service/offer...Id=5889&page=1
I tried configuring the script in Js Fiddle, but it didn't work. So you can use the following site: http://www.compileonline.com/try_javascript_online.php to run the script:
Code:
<!DOCTYPE html>
<html>
<head>
<title>Cross XML Sample</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<script src="xml2json.js"></script>
<script src="jquery.xdomainajax.js"></script>
<script>
<!-- XMLs de amostra:
// http://www.w3schools.com/xml/cd_catalog.xml
// http://bws.buscape.com/service/offers/lomadee/65717751673178504d42633d/BR/?sourceId=28400481&advertiserId=5889&page=1
-->
// For This example, im going to use sample xml from o'reily for practice
// located at url http://examples.oreilly.com/9780596002527/examples/first.xml
// We are going to extract character name nodes for this sample
function xmlLoader(){
$.ajax({
url: 'http://examples.oreilly.com/9780596002527/examples/first.xml',
dataType: "xml",
type: 'GET',
success: function(res) {
var myXML = res.responseText;
// This is the part xml2Json comes in.
var JSONConvertedXML = $.xml2json(myXML);
$('#myXMLList').empty();
for(var i = 0; i < JSONConvertedXML.book.character.length; i++){
$('#myXMLList').append('<li><a href="#">'+JSONConvertedXML.book.character[i].name+'</a></li>')
}
$('#myXMLList').listview('refresh');
$.mobile.hidePageLoadingMsg();
}
});
}
$( document ).delegate("#home", "pageshow", function() {
$.mobile.showPageLoadingMsg();
xmlLoader();
});
</script>
</head>
<body>
<div data-role="page" id="home">
<div data-role="header">
<h1>Sample Cross Domain XML</h1>
</div>
<div data-role="content">
<ul data-role="listview" data-theme="c" id="myXMLList">
</ul>
</div>
<div data-role="footer">
<a href="www.isgoodstuff.com" data-role="button">isGoodStuff.com</a>
</div>
</div>
</body>
</html>