If it looks like XML...

And walks and talks like XML, it surely must be XML. Yes, well how wrong you can be about assumptions is once more shown in this blog.

One of our clients has an application through which videos are streamed. They do this by providing a browser embedded player, or your stand-alone Windows Media Player with an ASX file. The ASX file tends to look like this:


  
    
  

So far so good. As long as that "video.wmv" exists, it will be played correctly by the Windows Media Player. Our client however requested that we add metadata from a database to the ASX file, so that when it is played in your stand-alone Windows Media Player, you will see the title, author and publication date of the video and a logo of the company. The problem however was that we don't generate these ASX files, they exist on the streaming server. This meant that we needed to read the ASX files on the fly, change them and send the response to the requesting client.

Because of the format we decided to use Dom4J to parse the XML and create a DOM tree of the ASX. We then added nodes to the DOM document, and wrote the resulting XML to the response stream. The XML which was the result of this exercise looked like the following:



  
    00:00:10.00
    
  
  
    Title of the video
    Xebia
    2007-08-17
    
  

This is valid XML. But all of a sudden, the videos didn't play anymore in Windows Media Player. After re-checking each of the tags carefully with the ASX Elements Reference on MSDN, we couldn't find what was wrong with this ASX file. That was, until we read the following statement here:

"... The first four characters of an ASX file must be <ASX. ..."

Wait a minute, that means it is XML, but you cannot include the XML preamble?!... After discarding the preamble from the result XML, the file suddenly worked again, and the video was streamed. The valuable lesson here of course is that If it looks, walks, talks and acts like XML, it still just might not be real XML.

Comments (3)

  1. Lars Vonk - Reply

    August 17, 2007 at 10:15 am

    As Homer would say: "Doh!"

  2. Robert van Loghem - Reply

    August 17, 2007 at 10:24 am

    As if Microsoft would have it any other way! 😉

    "Embrace and Extend" eh...no in this case "Embrace and Detract"

  3. Nico - Reply

    August 17, 2007 at 7:49 pm

    Yeah, IE does something similar, if you don't specify the DOCTYPE on the first line in your strict xhtml webpage, IE won't recognize, however to be strict xhtml you have to specify the XML preamble on the first line...

Add a Comment