1

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

Tim Post
  • 33,371
  • 15
  • 110
  • 174
Preet_Android
  • 2,332
  • 5
  • 25
  • 43
  • possible duplicate of [XML parsing of a variable string in JavaScript](http://stackoverflow.com/questions/649614/xml-parsing-of-a-variable-string-in-javascript) – Caleb Jun 19 '12 at 05:43
  • Thanks a lot... I get the solution... In this function i've to use " getattribute("UserId"); " instead of " getElementByTagName("UserId"); " Thank You. – Preet_Android Jun 19 '12 at 06:24

1 Answers1

1

You should try this:

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

Vilius Gaidelis
  • 430
  • 5
  • 14