Work-around for XMLDecoder Bug #SDK-17271

View Flex Bug #SDK-17271

After a whole bunch of digging around under the hood of the mx.rpc.XMLDecoder class, I finally pinpointed the line that is causing it to incorrectly decode elements that do not have sub-elements. Basically, when it gets to an element that it considers to have simple content (meaning just a string value between the tags), it immediately returns that string value and moves on to the next node. So, in the case of an empty node (like the one below), which has no inner value but only attributes, XMLDecoder would never even try to parse the attributes.


The solution was to check if the inner value evaluated to an empty string, and if it does, continue on as though it were actually a complex node, which will then parse the attributes.

Patch for Flex Bug #SDK-17271

Patch for Flex Bug #SDK-17271

I’ve created an example that decodes some simple xml data against a simple schema. By checking the “Patch” box, you can see that fix returns a object graph with the correct properties for the CarVO. This example would also be a good starting point if you’re interested in learning how to decode xml into strongly-typed objects. With the exception of this bug, the XMLDecoder class seems pretty solid, and it’s really handy if you want to parse something, like, say an MXML file.

View Example
View Source

Note: You could try pasting in your schema and data, but it’s not likely to work since you have to register class types with their qualified names in the schema. I’m still working out a way to do this dynamically from the schema.

This entry was posted in Flex and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.


  1. Ryan
    Posted April 29, 2009 at 8:11 am | Permalink

    Yeay for XMLDecoder hacking. I recently created an extended version of SOAPDecoder (which in turn extends XMLDecoder) and overrode decodeType to force dateTime values in SOAP messages to UTC time if they don’t have a time zone designator. (By default Flex interprets these as local time).

    I’d really like to see some better examples somewhere on how to use the schema type registry or whatever it’s called to directly generate strongly-typed VO objects. Adobe’s documentation seems a bit scant…

  2. Posted September 22, 2009 at 5:20 am | Permalink


    This post helped me a lot as I was stuck with the exact problem you have mentioned here.

    Thanks a ton!!!

  3. Posted September 24, 2009 at 3:55 pm | Permalink

    Great work. Thank you.

    How would you change this code if you wanted to return an ArrayCollection of CarVO objects instead of just a single one?

  4. Max G√ľnther
    Posted November 30, 2010 at 6:22 am | Permalink

    first thanks for this.
    I had to extend it further to

    if (value.hasSimpleContent() && (value[0] != null && value[0].toString() != “” ) )

    that is: First ensure value[0] != null before accessing it via []

    cheers Max

  5. Tim John
    Posted January 25, 2012 at 12:41 pm | Permalink

    Thank you! It took me all day to realise that empty tags weren’t being parsed. Thought it was my mistake. You’ve solved my problem in a jiffy! And nice one Max for the extra check.

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>