3
\$\begingroup\$

Could you please review the following? My concern is XML parsing is hardcoded:

 Ext.Ajax.request({
 url: storageDataItem.contentlink,
 success: function (response) {
 var store;
 try {
 var parser = new DOMParser();
 // TODO: remove extra lines or ignore on parsing. How? :)
 var xml = parser.parseFromString(response.responseText, "text/xml");
 var mediaContentURL = response.responseXML.childNodes[0].childNodes[0].childNodes[1].lastChild.attributes[0].nodeValue;
 var title = xml.getElementsByTagName('title')[1].childNodes[0].nodeValue;
 } catch (e) {
 // ignore exception
 }
 console.log("storage: ")
 }
 });
 this.fireEvent("playButtonTapped", storageDataItem);
 this.fireEvent("playAudioFile", title, mediaContentURL);

The actual feed

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked May 8, 2013 at 1:39
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

From looking a little into this

  • You derive mediaContentURL through response.responseXML and title through xml, I would stick in both cases to xml
  • As you guessed, your approach to getting the mediaContentURL is pretty terrible.
  • Use getElementsByTagName and attributes, do not hardcode array indexes
  • Do not use console.log in production code

I would use something like this:

function getItemTitle( xml , itemNumber )
{
 //Skip the title number of the playlist
 return xml.getElementsByTagName('title')[itemNumber+1].textContent
}
function getItemURL( xml , itemNumber )
{
 return xml.getElementsByTagName('content')[itemNumber].attributes.getNamedItem('url').value;
}
answered Apr 1, 2014 at 1:34
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.