XSPF to JSPF Parser in Javascript

This is a parser released under the LGPL 3, which allows you to parse and use XSPF playlists in your browser-side javascript code. It outputs a Javascript object that conforms to the specification of JSPF. It is hoped that by standardizing a JSON format for XSPF, an ecosystem of free browser based music players will arise.

This document will run the specifications for the XSPF.toJSPF parser. The output should appear in the firebug console (or firebug lite if firebug is not available.) You can also paste XSPF documents into the textarea below to have them parsed. An excellent source of example XSPF files is the XSPF testcase collection in the Xiph repository.

Contact Chris Anderson

Usage

Usage is simple. First, acquire an XML DOM for the XSPF you wish to parse. (see below.) Now that you have the xml document object, just pass it to the parser.

      var jspf = XSPF.toJSPF(xmldom);
    
Accessing values is easy. The style is plain old javascript:
      var title = jspf.playlist.title;
      var tracks = jspf.playlist.track;
      var first_annotation = tracks[0].annotation;
      var first_location = tracks[0].location[0];
    
The complete reference to the JSPF object is contained in the specification. If you don't have Firebug, get it, it will let you just click around the object graph. There is no more useful Javascript coder's tool.

Getting an XML DOM.

If you are requesting the XSPF using ajax you can usually get the responseXML directly from the transport object. Sometimes headers don't make this easy, or for whatever reason you may have an XSPF string but no DOM. There is a helper function which turns a string into a DOM.

      var xmldom = XSPF.XMLfromString(xspf_string);
    

Features

Known issues

Try it out


The output of the parser should appear here.