rv = nsComponentManager::CreateInstance(kCParserCID, nsnull, kCParserIID, (void **)&parser);
rv = EncodeToString(buf);
nsTextEncoder::EncodeToStream(nsIOutputStream* aStream){  nsresult rv;  if (!mDocument)    return NS_ERROR_NOT_INITIALIZED;  // xxx Also make sure mString is a mime type "text/html" or "text/plain"    if (mDocument)  {    nsString buffer;    mDocument->CreateXIF(buffer,mSelection);        nsString*     charset = nsnull;    nsAutoString  defaultCharset; defaultCharset.AssignWithConversion("ISO-8859-1");    if (!mCharset.EqualsWithConversion("null") && !mCharset.IsEmpty())      charset = &mCharset;     nsIParser* parser;    rv = nsComponentManager::CreateInstance(kCParserCID,                                             nsnull,                                             kCParserIID,                                             (void **)&parser);    if (NS_SUCCEEDED(rv)) {      nsIHTMLContentSink* sink = nsnull;      if (mMimeType.EqualsWithConversion("text/html"))        rv = NS_New_HTML_ContentSinkStream(&sink, aStream, charset, mFlags);      else        rv = NS_New_HTMLToTXT_SinkStream(&sink, aStream, charset,                                         mWrapColumn, mFlags);      if (NS_SUCCEEDED(rv))      {        parser->SetContentSink(sink);        nsIDTD* dtd = nsnull;        rv = NS_NewXIFDTD(&dtd);        if (NS_SUCCEEDED(rv))        {          parser->RegisterDTD(dtd);          parser->Parse(buffer, 0, NS_ConvertToString("text/xif"), PR_FALSE, PR_TRUE);        }        NS_IF_RELEASE(dtd);        NS_IF_RELEASE(sink);      }      NS_RELEASE(parser);    }	}  return rv;}