--- created_at: '2013-11-15T10:54:50.000Z' title: We have an employee whose last name is Null (2010) url: http://stackoverflow.com/questions/4456438/how-can-i-pass-the-string-null-through-wsdl-soap-from-actionscript-3-to-a-co?rq=1 author: gojko points: 67 story_text: '' comment_text: num_comments: 35 story_id: story_title: story_url: parent_id: created_at_i: 1384512890 _tags: - story - author_gojko - story_6738743 objectID: '6738743' year: 2010 --- # Tracking it down At first I thought this was a coercion bug where `null` was getting coerced to `"null"` and a test of `"null" == null` was passing. It's not. **I was close, but so very, very wrong. Sorry about that\!** I've since done lots of [fiddling on wonderfl.net](http://wonderfl.net/c/dd23/read) and tracing through the code in `mx.rpc.xml.*`. At line 1795 of `XMLEncoder` (in the 3.5 source), in `setValue`, all of the XMLEncoding boils down to currentChild.appendChild(xmlSpecialCharsFilter(Object(value))); which is essentially the same as: currentChild.appendChild("null"); This code, according to my original fiddle, returns an empty XML element. But why? # Cause According to commenter Justin Mclean on bug report [FLEX-33664](https://issues.apache.org/jira/browse/FLEX-33644), the following is the culprit (see last two tests in my [fiddle](http://wonderfl.net/c/dd23/read) which verify this): var thisIsNotNull:XML = null; if(thisIsNotNull == null){ // always branches here, as (thisIsNotNull == null) strangely returns true // despite the fact that thisIsNotNull is a valid instance of type XML } When `currentChild.appendChild` is passed the string `"null"`, it first converts it to a root XML element with text `null`, and then tests that element against the null literal. This is a weak equality test, so either the XML containing null is coerced to the null type, or the null type is coerced to a root xml element containing the string "null", and the test passes where it arguably should fail. One fix might be to always use [strict equality](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/operators.html#strict_equality) tests when checking XML (or anything, really) for "nullness." # Solution The only reasonable workaround I can think of, short of fixing this bug in every damn version of ActionScript, is to test fields for "null" and **escape them as [CDATA values](https://stackoverflow.com/q/1239466/203705).** The only reasonable workaround I can think of, short of fixing this bug in every damn version of ActionScript, is to test fields for "null" and **CDATA values are the most appropriate way to mutate an entire text value that would otherwise cause encoding/decoding problems.** Hex encoding, for instance, is meant for individual characters. CDATA values are preferred when you're escaping the entire text of an element. The biggest reason for this is that it maintains human readability.