         {
             if (child.nodeKind() == "element")
             {
-                var element:XML = child;
-                var href:String = getAttributeFromNode("href", element);
+                var href:String = getAttributeFromNode("href", child);
                 if (href != null)
                 {
                     var hashPosition:int = href.indexOf("#");
                     if (hashPosition >= 0)
                         href = href.substring(hashPosition + 1);
-    
+
                     // Find the first element with a matching id attribute 
                     var matches:XMLList = _elementsWithId.(@id == href);
                     var referent:XML;
-                    
+
                     if (matches.length() > 0)
                         referent = matches[0];
                     else
                         throw new Error("The element referenced by id '" + href + "' was not found.");
-                        
-                    referent.setName(element.name());
-                    
+
+                    referent.setName(child.name());
+
                     if (referent.hasComplexContent())
                         resolveReferences(referent, false);
-                        
+
+                    // Replace the reference with the referent
                     root.replace(index, referent);
-                }
-                else if (element.hasComplexContent())
-                {
-                    resolveReferences(element, false);
+
+                    // Then remove the id attribute from replaced value
+                    referent = root.child(index)[0];
+                    delete referent.@id;
+                }
+                else if (child.hasComplexContent())
+                {
+                    resolveReferences(child, false);
                 }
             }
 
             index++;
         }
-        
+
         if (cleanupElementsWithIdCache)
         {
             _elementsWithId = null;

import flash.xml.XMLDocument;
import flash.xml.XMLNode;

import mx.collections.IList;
import mx.core.mx_internal;
import mx.logging.ILogger;
import mx.logging.Log;
import mx.rpc.soap.types.ICustomSOAPType;
import mx.rpc.wsdl.WSDLMessagePart;
import mx.rpc.wsdl.WSDLConstants;
import mx.rpc.wsdl.WSDLEncoding;
import mx.rpc.wsdl.WSDLOperation;
import mx.rpc.xml.ContentProxy;
import mx.rpc.xml.DecodingContext;

     */
    private function resolveReferences(root:XML, cleanupElementsWithIdCache:Boolean=true):void
    {
        if (_referencesResolved)
            return;

        var index:uint = 0;
        if (_elementsWithId == null)
            _elementsWithId = document..*.(attribute("id").length() > 0);

        // Note that we must consider all child nodes here, not just elements
        // as we need the accurate index in terms of child XML nodes to replace
        // a node with the referent.
