简体   繁体   中英

PhoneGap - How to parse an xml string using javascript

I'm developing an application in phone gap. In this i've to parse an xml to get the data and display in my app. Below I've given the XML from which I've to get data.

<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>

So can anyone tell me how to get the data from the xml string.

Thanks in Advance


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;
        }

//

i'm using this code to get the value from the xml. But the value in i've get is nothing(Undefined).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM