Blog

If it looks like XML…

17 Aug, 2007
Xebia Background Header Wave

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.

Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts