bestway to parse xml services in javascript?
I am new to javascript.I wanted to parse xml and displayed in javascript.I used the following code.it did not give output?any help please? what is advantage if we use jQuery and difference between normal javascript and jQuery?`
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.get("http://www.hindu.com/rss/01hdline.xml", function(response){
var response = $.paseXML(response);
var $xml = $(response);
//Now y开发者_Python百科ou can find any xml node with $xml using various methods of jQuery
//E.g
alert($xml.find( "title" ));
});
});
If you used jQuery
you dont have to write all the code which you have written, jQuery
will do it for you and it works across all the browsers. Also it has built in utility to parse xml using which you can easily traverse through the xml document and write you logic. Try this
$.get("http://www.hindu.com/rss/01hdline.xml", function(response){
var response = $.paseXML(response);
var $xml = $(response);
//Now you can find any xml node with $xml using various methods of jQuery
//E.g
alert($xml.find( "title" ));
});
The reason your code is not working because
You cannot do cross-domain XMLHttpRequests.
You might instead consider either XMLHttp-request your own server to fetch the remote XML content for you (php script, for example)
精彩评论