• Custom XML model binder for ASP.NET MVC

    In an earlier post I wrote about using an XML value provider to allow you to send XML to your .NET MVC action methods. This is great, until you want to accept XML where you have a model that needs XML attributes to control how it's deserialized. As the value provider stage happens before model binding it has no knowledge of the model objects that the values will be pushed into. So it can't look at your model class's XML attributes.

    In cases like this, you're better of using a custom XML model binder.

    To setup an XML model binder you need to create a model binder and a model binder provider. …

  • Sending XML to an ASP.NET MVC Action Method Argument

    I read a great article recently by Phil Haack on sending JSON to an action method. This was very timely as I wanted to do exactly that in the REST API I've been creating for Kensei, a video hosting website. However, I wanted to make it work with XML as well as JSON.

    Phil Haack creates something called a JSON value provider, so I followed his example and created an XML value provider. I've used it on two projects now and it's worked a treat. I thought I'd share it with the world in the hope that it will be useful to others.

    Source code

    XML Value Provider (C# source)

    To get this working in your …

  • ActionScript 3 timeout problems when working with XML

    I was getting the following error while developing my doodle flash application using ActionScript 3.0:

    1502 A script has executed for longer than the default timeout period of 15 seconds.

    I tracked the problem down to a piece of code that looped through a large XML document. At first I thought there was nothing I could do, but after playing about with it and pulling my hair out for a while I found out several things that helped me reduce the runtime by an impressive amount. I wanted to share my findings in case anyone else was having similar problems.

    Finding 1: XML .. operator is very slow …

  • Sending a list into an SQL stored procedure using XML

    I wanted to pass a list of user IDs into a stored procedure. What I really wanted was to be able to pass an array, but you're not able to do that because it would be too easy. It took me quite a while to figure this out, but now I know how, it'll be easy next time.

    There's a nice set of functions that allow you to get values from an XML string and treat the set of values like a table. Just what I wanted from arrays really.

    Here is the XML string that I used:


    <user id="24" />

    <user id="27" />


    And here is the relevant part of the stored procedure I …