【问题标题】:PhoneGap - How to parse an xml string using javascriptPhoneGap - 如何使用 javascript 解析 xml 字符串
【发布时间】:2012-06-21 03:17:33
【问题描述】:

我正在开发一个电话间隙的应用程序。在此我必须解析一个 xml 以获取数据并显示在我的应用程序中。 下面我给出了我必须从中获取数据的 XML。

<Result>
<Art Transaction="event/listAllUsersXml" Success="True"/>
<ExhibitorAndSponsor UserID="60" UserName="Economy Times" UserPhoto="http://www.bestbusinessplaces.com/event/admin/logos/big/100X100.gif" Latitude="" Longitude="" Country="" UserType="SponsorAndExhibitor"/>
<ExhibitorAndSponsor UserID="61" UserName="Cadbury" UserPhoto="http://www.bestbusinessplaces.com/event/admin/logos/big/100X100.gif" Latitude="" Longitude="" Country="Andorra" UserType="SponsorAndExhibitor"/>
<ExhibitorAndSponsor UserID="62" UserName="Pepsi" UserPhoto="http://www.bestbusinessplaces.com/event/admin/logos/big/100X100.gif" Latitude="" Longitude="" Country="" UserType="SponsorAndExhibitor"/>
</Result>

那么谁能告诉我如何从 xml 字符串中获取数据。

提前致谢


function displayData(){
            UserID = (x[i].getElementsByTagName("UserID")[0]);
            UserName = (x[i].getElementsByTagName("UserName")[0]);
            UserType = (x[i].getElementsByTagName("UserType")[0]);
            txt = "UserID: " + UserID + "<br />UserName: " + UserName + "<br />UserType: "+ UserType;
            document.getElementById("showCD").innerHTML = txt;
        }

//

我正在使用此代码从 xml 中获取值。但是我得到的值是什么(未定义)。

【问题讨论】:

标签: javascript cordova xml-parsing


【解决方案1】:

你应该试试这个:

http://api.jquery.com/jQuery.parseXML/

【讨论】:

    猜你喜欢
    • 2012-04-08
    • 1970-01-01
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 2010-12-23
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多