if (aSource == nsnull) {
PRUint16 typeValue; nsresult rv = aSource->GetDataType(&typeValue); NS_ENSURE_SUCCESS(rv, rv);  if (typeValue != nsIDataType::VTYPE_ARRAY) { return NS_ERROR_FAILURE; }  nsIID iid; PRUint32 count; void* array; rv = aSource->GetAsArray(&typeValue, &iid, &count, &array); NS_ENSURE_SUCCESS(rv, rv);  if (typeValue != nsIDataType::VTYPE_UINT8) { return NS_ERROR_FAILURE; }  char* encodedVal = PL_Base64Encode(NS_STATIC_CAST(const char*, array), count, nsnull); if (!encodedVal) { return NS_ERROR_FAILURE; } nsAdoptingCString encodedString(encodedVal);  nsAutoString name, ns; if (aName.IsEmpty()) {  rv = aEncoding->GetStyleURI(ns); NS_ENSURE_SUCCESS(rv, rv); name.Append(gSOAPStrings->kBase64BinarySchemaType); } else { name = aName;  }  nsCOMPtr<nsIDOMDocument> document; rv = aDestination->GetOwnerDocument(getter_AddRefs(document)); NS_ENSURE_SUCCESS(rv, rv);  nsCOMPtr<nsIDOMElement> element; rv = document->CreateElementNS(ns, name, getter_AddRefs(element)); NS_ENSURE_SUCCESS(rv, rv);  nsCOMPtr<nsIDOMNode> ignore; rv = aDestination->AppendChild(element, getter_AddRefs(ignore)); NS_ENSURE_SUCCESS(rv, rv);  if (aSchemaType) { nsAutoString typeName, typeNS; rv = aSchemaType->GetName(typeName); NS_ENSURE_SUCCESS(rv, rv); rv = aSchemaType->GetTargetNamespace(typeNS); NS_ENSURE_SUCCESS(rv, rv);  nsAutoString qname; rv = nsSOAPUtils::MakeNamespacePrefix(nsnull, element, typeNS, qname); NS_ENSURE_SUCCESS(rv, rv);  qname.Append(gSOAPStrings->kQualifiedSeparator + typeName);
    nsDefaultEncoder::Encode(nsISOAPEncoding * aEncoding,                             nsIVariant * aSource,                             const nsAString & aNamespaceURI,                             const nsAString & aName,                             nsISchemaType * aSchemaType,                             nsISOAPAttachments * aAttachments,                             nsIDOMElement * aDestination,                             nsIDOMElement * *aReturnValue){  NS_ENSURE_ARG_POINTER(aEncoding);  NS_ENSURE_ARG_POINTER(aDestination);  NS_ENSURE_ARG_POINTER(aReturnValue);  *aReturnValue = nsnull;  if (aSource == nsnull) {    nsAutoString ns;    nsCOMPtr<nsIDOMElement> cloneable;    nsresult rc = aEncoding->GetExternalSchemaURI(gSOAPStrings->kXSIURI, ns);    if (NS_FAILED(rc))      return rc;    nsAutoString name;    if (!aName.IsEmpty())      name.Assign(gSOAPStrings->kNull);    rc = EncodeSimpleValue(aEncoding, gSOAPStrings->kEmpty, gSOAPStrings->kEmpty,       name, nsnull, aDestination, aReturnValue);    if (NS_FAILED(rc))      return rc;    rc = (*aReturnValue)->SetAttributeNS(ns, gSOAPStrings->kNull, gSOAPStrings->kTrueA);    if (NS_FAILED(rc))      return rc;  }  nsCOMPtr<nsISOAPEncoder> encoder;  if (aSchemaType) {    nsCOMPtr<nsISchemaType> lookupType = aSchemaType;    do {      nsAutoString schemaType;      nsAutoString schemaURI;      nsAutoString encodingKey;      nsresult rc = lookupType->GetName(schemaType);      if (NS_FAILED(rc))        return rc;      rc = lookupType->GetTargetNamespace(schemaURI);      if (NS_FAILED(rc))        return rc;      SOAPEncodingKey(schemaURI, schemaType, encodingKey);      rc = aEncoding->GetEncoder(encodingKey, getter_AddRefs(encoder));      if (NS_FAILED(rc))        return rc;      if (encoder)        break;      nsCOMPtr<nsISchemaType> supertype;      rc = GetSupertype(aEncoding, lookupType, getter_AddRefs(supertype));      if (NS_FAILED(rc))        return rc;      lookupType = supertype;    }    while (lookupType);  }  if (!encoder) {    nsAutoString encodingKey;    SOAPEncodingKey(gSOAPStrings->kXSURI,                    gSOAPStrings->kAnyTypeSchemaType, encodingKey);    nsresult rc =        aEncoding->GetEncoder(encodingKey, getter_AddRefs(encoder));    if (NS_FAILED(rc))      return rc;  }  if (encoder) {    return encoder->Encode(aEncoding, aSource, aNamespaceURI, aName,                           aSchemaType, aAttachments, aDestination,                           aReturnValue);  }  return SOAP_EXCEPTION(NS_ERROR_NOT_IMPLEMENTED,"SOAP_NO_ENCODER_FOR_TYPE","The default encoder finds no encoder for specific type");}