0

I am looking to parse XML data (using this URL: https://gdata.youtube.com/feeds/api/videos/ijudAdhLGmg?v=2) and get the contents of the title element and store it in a variable so I can use it later in my script. I am new to JQuery and I am not sure how to do this.

1
  • cant you just add &alt=json to the url? Commented Jan 28, 2012 at 6:22

4 Answers 4

2

code below will fetch the xml from the url and get the title

$.ajax({
   url:"https://gdata.youtube.com/feeds/api/videos/ijudAdhLGmg?v=2",
   dataType:"xml",
   crossDomain: true,
   success:function(html){
      var title = $(html).find("title")[0];
   }
});

however the problem you might face is the cross site problem, where modern browser will not allow ajax to call an url that not the same as the host

Sign up to request clarification or add additional context in comments.

Comments

1
var xml    = "your xml string here",
    xmlDoc = $.parseXML(xml),
    $xml   = $(xmlDoc),
    $title = $xml.find("title");

Comments

1

You can check the jQuery online doc.

This one is for jQuery to parse XML: jQuery.parseXML()

Comments

0

you can use .psrseXML for the parsing

$.ajax({
    url:'https://gdata.youtube.com/feeds/api/videos/ijudAdhLGmg?v=2',
    type:'GET',
    dataType:'jsonp',
    success:function(data){
    //console.log(data);
        var xml    = data,
        xmlDoc = $.parseXML(xml),
        $xml   = $(xmlDoc),
        $mediaDes = $xml.find("media\\:description").text();
        console.log($mediaDes );
    }
});

the data in the success callback contains the xml

DEMO

1 Comment

@user1126921 you will have to parse the xml and append the wanted values using append or appendTo functions you can search them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.