如何用jquery/javascript读取xml文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用jquery/javascript读取xml文件相关的知识,希望对你有一定的参考价值。
//Perform when the document is ready/loaded/rendered $(document).ready(function(){ //Asynchronously retrieve the xml file contents $.ajax({ type: "GET", url: "sites.xml", dataType: "xml", success: function(xml) { //Upon successful retrieval //Iterate through the all the nodes/items $(xml).find('site').each(function(){ //For each item, perform the following //Read each child node and associate the values with a variable var id = $(this).attr('id'); //Find an attribute within the "site" node/element var title = $(this).find('title').text(); //Find the child element of "site" called title var url = $(this).find('url').text(); //Find the child element of "site" called title //Write out a custom link with the values above $('<div class="items" id="link_'+id+'"></div>').html('<a href="'+url+'">'+title+'</a>').appendTo('#page-wrap'); //Establish the "desc" node/element as the this value below, to be referenced fro child nodes/elements $(this).find('desc').each(function(){ var brief = $(this).find('brief').text(); var long = $(this).find('long').text(); $('<div class="brief"></div>').html(brief).appendTo('#link_'+id); $('<div class="long"></div>').html(long).appendTo('#link_'+id); }); }); } }); });
以上是关于如何用jquery/javascript读取xml文件的主要内容,如果未能解决你的问题,请参考以下文章
android程序中 客户端如何用pull 读取远程服务器上的xml文件? 请给出代码。谢谢。