             newNode.nodeName = XObjUtils.encodeElementTag(qname, newNode);
             return newNode;
         }
+        else if (isRoot)
+        {
+            return internal_encodeValue(obj, qname, parentNode);
+        }
         else if (referenceOnly)
         {
             return internal_encodeValue(obj, qname, parentNode, false, true);

            parentNode.parentNode = xmlDocument;
        }
        
        encodeValue(obj, qname, parentNode);
        
        return xmlDocument;
    }
    
    public function encodeReference(obj:Object, q:*, parentNode:XMLNode):XMLNode
    {
        return encodeValue(obj, q, parentNode, false, true);
    }
    
    public function encodeValue(obj:Object, q:*, parentNode:XMLNode, recurse:Boolean=true, referenceOnly:Boolean=false):XMLNode
    {
        var qname:XObjQName = new XObjQName();
        

        }
    }
    
    internal function internal_encodeValue(obj:Object, 
                                            qname:XObjQName, 
                                            parentNode:XMLNode, 
                                            recurse:Boolean=true, 
