Jeevan Dongre
Jeevan Dongre

Reputation: 4647

parsing xml file and displaying the content using jquerymobile

I am new to Jquery mobile environment. I have an XML file and I need to parse it and display the content using JqueryMobile.

this is the format of XML:

<Result>
  <Details>
    <Attendee>
      <AttendeeID>1</AttendeeID>
      <Name>krishna</Name>
      <AttendeeEmail>[email protected]</AttendeeEmail>
      <AttendeeMobile>9876543210</AttendeeMobile>
      <AttendeeProfession>Android</AttendeeProfession>
      <AttendeeTagCloud>Developers</AttendeeTagCloud>
    </Attendee>
    <Response>Success</Response>
    <Count>1</Count>
  </Details>
</Result>

I tried Google-ing it but couldn't find anything that would help me out.

Kindly help me solve this.I am not able to solve the xml tags

Upvotes: 0

Views: 7897

Answers (2)

Deon
Deon

Reputation: 97

This is what I use to pull a remote xml that is dynamically rendered on my web server.

Code that retrieves the xml file from server:

<script>
$(document).ready(function(){

       $.ajax({
               type: "GET",
               url: "YOUR URL TO THE XML FILE ON THE SERVER",
               dataType: "xml",
               success: parseXml
               });

Code that parses the xml file in jquery mobile:

function parseXml(xml) {
$(xml).find('YOUR XML RECORD NODE FIELD').each(function(){
                  $("YOUR DIV ID/CLASS IN YOUR JQUERY MOBILE PAGE").append('SOME HTML CODE LIKE <li><h3>') + $(this).find("FIELD TO DISPLAY FROM YOUR XML RECORD").text() + 'CLOSING HTML CODE FROM ABOVE </h3></li>');
 });
}
});
</script>

Hope that helps.

Upvotes: 1

Rafay
Rafay

Reputation: 31043

use .parseXML

 xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc ),
    $email= $xml.find( "AttendeeEmail" ).text();

alert($email);

here is the fiddle http://jsfiddle.net/WPV9B/

Upvotes: 2

Related Questions