if (NS_FAILED(rc)) return rc; needType = (!typeName.IsEmpty()                   && !(typeName.Equals(gSOAPStrings->kAnyTypeSchemaType) && typeNS.Equals(gSOAPStrings->kXSURI)));
NS_ENSURE_SUCCESS(rc, rc);
EncodeSimpleValue(nsISOAPEncoding * aEncoding,                  const nsAString & aValue,                  const nsAString & aNamespaceURI,                  const nsAString & aName,                  nsISchemaType * aSchemaType,                  nsIDOMElement * aDestination, nsIDOMElement ** _retval){  nsresult rc;  PRBool needType = PR_FALSE;  nsAutoString typeName;  nsAutoString typeNS;  if (aSchemaType) {    rc = aSchemaType->GetName(typeName);    if (NS_FAILED(rc))      return rc;    rc = aSchemaType->GetTargetNamespace(typeNS);    if (NS_FAILED(rc))      return rc;    needType = (!typeName.IsEmpty()                   &&                !(typeName.Equals(gSOAPStrings->kAnyTypeSchemaType) &&                 typeNS.Equals(gSOAPStrings->kXSURI)));  }  nsAutoString name;      //  First choose the appropriate name and namespace for the element.  nsAutoString ns;  if (aName.IsEmpty()) {  //  We automatically choose appropriate element names where none exist.    // The idea here seems to be to walk up the schema hierarchy to    // find the base type and use the name of that as the element name.    ns = gSOAPStrings->kSOAPEncURI;    nsAutoString currentURI = ns;    nsCOMPtr<nsISchemaType> currentType = aSchemaType;    while (currentType           && !(currentURI.Equals(gSOAPStrings->kXSURI)                || currentURI.Equals(gSOAPStrings->kSOAPEncURI))) {      nsCOMPtr<nsISchemaType> supertype;      rc = GetSupertype(aEncoding, currentType, getter_AddRefs(supertype));      if (NS_FAILED(rc))        return rc;      if (!currentType) {        break;      }      currentType = supertype;      rc = currentType->GetTargetNamespace(currentURI);      if (NS_FAILED(rc))        return rc;    }    if (currentType) {      rc = aSchemaType->GetName(name);      if (NS_FAILED(rc))        return rc;      needType = needType && (currentType != aSchemaType);  //  We may not need type    }    else {      name = gSOAPStrings->kAnyTypeSchemaType;      needType = PR_FALSE;    }    rc = aEncoding->GetExternalSchemaURI(gSOAPStrings->kSOAPEncURI, ns);  }  else {    name = aName;    rc = aEncoding->GetExternalSchemaURI(aNamespaceURI, ns);  }  if (NS_FAILED(rc))    return rc;  nsCOMPtr<nsIDOMDocument> document;  rc = aDestination->GetOwnerDocument(getter_AddRefs(document));  if (NS_FAILED(rc))    return rc;  nsCOMPtr<nsIDOMElement> element;  rc = document->CreateElementNS(ns, name, getter_AddRefs(element));  if (NS_FAILED(rc))    return rc;  nsCOMPtr<nsIDOMNode> ignore;  rc = aDestination->AppendChild(element, getter_AddRefs(ignore));  if (NS_FAILED(rc))    return rc;  if (needType) {    nsAutoString type;    rc = nsSOAPUtils::MakeNamespacePrefix(aEncoding, element,                                            typeNS, type);    if (NS_FAILED(rc))      return rc;    type.Append(gSOAPStrings->kQualifiedSeparator);    type.Append(typeName);    rc = aEncoding->GetExternalSchemaURI(gSOAPStrings->kXSIURI, ns);    if (NS_FAILED(rc))      return rc;    rc = (element)->        SetAttributeNS(ns, gSOAPStrings->kXSITypeAttribute, type);    if (NS_FAILED(rc))      return rc;  }  if (!aValue.IsEmpty()) {    nsCOMPtr<nsIDOMText> text;    rc = document->CreateTextNode(aValue, getter_AddRefs(text));    if (NS_FAILED(rc))      return rc;    rc = (element)->AppendChild(text, getter_AddRefs(ignore));    if (NS_FAILED(rc))      return rc;  }  *_retval = element;  NS_IF_ADDREF(*_retval);  return rc;}