1

我正在开发一个电话间隙的应用程序。在此我必须解析一个 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 中获取值。但我得到的价值是什么(未定义)。

4

1 回答 1

1

你应该试试这个:

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

于 2012-06-19T05:42:28.073 回答