Gurpreets11
Gurpreets11

Reputation: 2351

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

Upvotes: 1

Views: 3242

Answers (1)

Vilius Gaidelis
Vilius Gaidelis

Reputation: 450

You should try this:

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

Upvotes: 1

Related Questions