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

        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


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;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.