         }
         else if (isRoot)
         {
-            return internal_encodeValue(obj, qname, parentNode);
+            return internal_encodeValue(obj, qname, parentNode, true, referenceOnly);
         }
         else if (referenceOnly)
         {

        
        myElement = xmlDocument.createElement("foo");
        
        if (referenceOnly)
        {
            // link us into the heirarchy so that namespaces
            // will be resolved up the chain correctly
            parentNode.appendChild(myElement);

                    encodeValue(member, qname, myElement, recurse);
            }
        }
        else // must be simple type
        {
            parentNode.appendChild(myElement);
