nsCOMPtr<nsIURI> uri; doc->GetDocumentURL(getter_AddRefs(uri));
int main (int argc, char* argv[]) {  nsresult                     rv;  nsCOMPtr<nsIURI>             pURI;  nsCOMPtr<nsIChannel>         pChannel;  nsCOMPtr<nsIInputStream>     pInputStream;  PRUint32                     uiContentLength;  nsCOMPtr<nsIDOMParser>       pDOMParser;  nsCOMPtr<nsIDOMDocument>     pDOMDocument;  nsCOMPtr<nsIXMLHttpRequest>  pXMLHttpRequest;  nsIServiceManager *servMgr;  rv = NS_InitXPCOM2(&servMgr, nsnull, nsnull);  if (NS_FAILED(rv)) return rv;  if (argc > 2) {    if (nsCRT::strcasecmp( argv[1], "parsestr" ) == 0) {      pDOMParser = do_CreateInstance( NS_DOMPARSER_CONTRACTID,                                     &rv );      if (NS_SUCCEEDED( rv )) {        nsString str; str.AssignWithConversion(argv[2]);        rv = pDOMParser->ParseFromString(str.get(),"text/xml",                                          getter_AddRefs( pDOMDocument ) );        if (NS_SUCCEEDED( rv )) {          printf( "DOM parse string of\n\n%s\n\nsuccessful\n", argv[2] );        }        else {          printf( "DOM parse of \n%s\n NOT successful\n", argv[2] );        }      }      else {        printf( "do_CreateInstance of DOMParser failed for %s - %08X\n", argv[2], rv );      }    } else if (nsCRT::strcasecmp( argv[1], "parse" ) == 0) {      // DOM Parser      rv = NS_NewURI( getter_AddRefs( pURI ),                      argv[2] );      if (NS_SUCCEEDED( rv )) {        rv = NS_NewChannel( getter_AddRefs( pChannel ),                         pURI,                         nsnull,                         nsnull );        if (NS_SUCCEEDED( rv )) {          rv = pChannel->Open( getter_AddRefs( pInputStream ) );          if (NS_SUCCEEDED( rv )) {            rv = pInputStream->Available(&uiContentLength );            if (NS_SUCCEEDED( rv )) {              pDOMParser = do_CreateInstance( NS_DOMPARSER_CONTRACTID,                                             &rv );              if (NS_SUCCEEDED( rv )) {                pDOMParser->SetBaseURI(pURI);                rv = pDOMParser->ParseFromStream( pInputStream,                                                  "UTF-8",                                                  uiContentLength,                                                  "text/xml",                                                  getter_AddRefs( pDOMDocument ) );                if (NS_SUCCEEDED( rv )) {                  printf( "DOM parse of %s successful\n", argv[2] );                }                else {                  printf( "DOM parse of %s NOT successful\n", argv[2] );                }              }              else {                printf( "do_CreateInstance of DOMParser failed for %s - %08X\n", argv[2], rv );              }            }            else {              printf( "pInputSteam->Available failed for %s - %08X\n", argv[2], rv );            }          }          else {            printf( "pChannel->OpenInputStream failed for %s - %08X\n", argv[2], rv );          }        }        else {          printf( "NS_NewChannel failed for %s - %08X\n", argv[2], rv );        }      }      else {        printf( "NS_NewURI failed for %s - %08X\n", argv[2], rv );      }    }    else if (nsCRT::strcasecmp( argv[1], "syncread" ) == 0) {      // Synchronous Read      pXMLHttpRequest = do_CreateInstance( NS_XMLHTTPREQUEST_CONTRACTID,                                          &rv );      if (NS_SUCCEEDED( rv )) {        rv = pXMLHttpRequest->OpenRequest( "GET",                                           argv[2],                                           PR_FALSE,                                           nsnull, nsnull );        if (NS_SUCCEEDED( rv )) {          rv = pXMLHttpRequest->Send( nsnull );          if (NS_SUCCEEDED( rv )) {            rv = pXMLHttpRequest->GetResponseXML( getter_AddRefs( pDOMDocument ) );            if (NS_SUCCEEDED( rv )) {              if (pDOMDocument) {                printf( "Synchronous read of %s successful, DOMDocument created\n", argv[2] );              }              else {                printf( "Synchronous read of %s NOT successful, DOMDocument NOT created\n", argv[2] );              }            }            else {              printf( "pXMLHttpRequest->GetResponseXML failed for %s - %08X\n", argv[2], rv );            }          }          else {            printf( "pXMLHttpRequest->Send failed for %s - %08X\n", argv[2], rv );          }        }        else {          printf( "pXMLHttpRequest->OpenRequest failed for %s - %08X\n", argv[2], rv );        }      }      else {        printf( "do_CreateInstance of XMLHttpRequest failed for %s - %08X\n", argv[2], rv );      }    }#if 0    else if (nsCRT::strcasecmp( argv[1], "load" ) == 0) {      nsMyListener * listener = new nsMyListener();      listener->Start(argv[2]);    }#endif    else {      usage( );    }  }  else {    usage( );  }  if (pDOMDocument) {    nsCOMPtr<nsIDOMElement> element;    pDOMDocument->GetDocumentElement(getter_AddRefs(element));    nsAutoString tagName;    if (element) element->GetTagName(tagName);    char *s = ToNewCString(tagName);    printf("Document element=\"%s\"\n",s);    nsCRT::free(s);    nsCOMPtr<nsIDocument> doc = do_QueryInterface(pDOMDocument);    if (doc) {      nsCOMPtr<nsIURI> uri;      doc->GetDocumentURL(getter_AddRefs(uri));      nsCAutoString spec;      uri->GetSpec(spec);      printf("Document URI=\"%s\"\n",spec.get());    }  }  if (servMgr)    rv = NS_ShutdownXPCOM(servMgr);    return rv;}