aOutputString.Append((PRUnichar)'\n');
nsDocumentEncoder::EncodeToString(nsAString& aOutputString){  if (!mDocument)    return NS_ERROR_NOT_INITIALIZED;  aOutputString.Truncate();  nsCAutoString progId(NS_CONTENTSERIALIZER_CONTRACTID_PREFIX);  progId.AppendWithConversion(mMimeType);  mSerializer = do_CreateInstance(progId.get());  NS_ENSURE_TRUE(mSerializer, NS_ERROR_NOT_IMPLEMENTED);  nsresult rv = NS_OK;  nsCOMPtr<nsIAtom> charsetAtom;  if (!mCharset.IsEmpty()) {    if (!mCharsetConverterManager) {      mCharsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);      NS_ENSURE_SUCCESS(rv, rv);    }  }  mSerializer->Init(mFlags, mWrapColumn, mCharset.get(), mIsCopying);  if (mSelection) {    nsCOMPtr<nsIDOMRange> range;    PRInt32 i, count = 0;    rv = mSelection->GetRangeCount(&count);    NS_ENSURE_SUCCESS(rv, rv);    for (i = 0; i < count; i++) {      mSelection->GetRangeAt(i, getter_AddRefs(range));      rv = SerializeRangeToString(range, aOutputString);      NS_ENSURE_SUCCESS(rv, rv);    }    mSelection = nsnull;  } else if (mRange) {      rv = SerializeRangeToString(mRange, aOutputString);      mRange = nsnull;  } else if (mNode) {    rv = SerializeToStringRecursive(mNode, aOutputString);    mNode = nsnull;  } else {    nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument));    rv = mSerializer->AppendDocumentStart(domdoc, aOutputString);    if (NS_SUCCEEDED(rv)) {      aOutputString.Append((PRUnichar)'\n');      nsCOMPtr<nsIDOMNode> doc(do_QueryInterface(mDocument));      rv = SerializeToStringRecursive(doc, aOutputString);    }  }  NS_ENSURE_SUCCESS(rv, rv);  rv = mSerializer->Flush(aOutputString);  return rv;}