加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何从服务器解析xml到我们的html页面中的phonegap应用程序

发布时间:2020-12-16 22:43:49 所属栏目:百科 来源:网络整理
导读:我是webdevelopment的新手,我想从网络服务器解析xml而不是从本地服务器解析它是怎么可能的.我尝试了很多googled.Please帮助我.我必须解析这个网址“http://twitter.com/statuses/ public_timeline.xml” 解决方法 你可以在 HTML页面中使用 JQuery( http://jq
我是webdevelopment的新手,我想从网络服务器解析xml而不是从本地服务器解析它是怎么可能的.我尝试了很多googled.Please帮助我.我必须解析这个网址“http://twitter.com/statuses/ public_timeline.xml”

解决方法

你可以在 HTML页面中使用 JQuery( http://jquery.com/)插件作为脚本标记中的条目,称为jquery的ajax()函数来命中url,你可以使用jquery的parseXML()和find()函数来解析xml数据
像这样-

<html>
<head>
<script src="js/jquery-1.4.2.js" type="text/javascript" charset="utf-8"></script>
<script>
function onBodyLoad(){
$.ajax({  
    url:'http://twitter.com/statuses/public_timeline.xml',dataType:"xml",contentType:'application/xml',timeout:10000,type:'POST',success:function(data) {  

    alert(data);
    var xmlDoc = $.parseXML( data ),$xml = $( xmlDoc ),$title = $xml.find( "title" );

    /* append "RSS Title" to #someElement */
    $( "#someElement" ).append( $title.text() );

    /* change the title to "XML Title" */
    $title.text( "XML Title" );

    /* append "XML Title" to #anotherElement */
    $( "#anotherElement" ).append( $title.text() );

    },error:function(XMLHttpRequest,textStatus,errorThrown) {     
      alert("Error status :"+textStatus);  
      alert("Error type :"+errorThrown);  
      alert("Error message :"+XMLHttpRequest.responseXML);  
    }});
}
</script>
</head>
<body onload="onBodyLoad()">
<p id="someElement"></p>
<p id="anotherElement"></p>
</body>
</html>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读