if (NS_FAILED(rv)) return NS_OK;
nsCOMPtr<nsIDOMDocument> domDoc; nsCOMPtr<nsISyncLoadDOMService> loader = do_GetService("@mozilla.org/content/syncload-dom-service;1", &rv); NS_ENSURE_SUCCESS(rv, rv);
nsXBLService::FetchBindingDocument(nsIURI* aURI, nsIDocument** aResult){  // Initialize our out pointer to nsnull  *aResult = nsnull;  // Create the XML document  nsCOMPtr<nsIDocument> doc;  nsresult rv = nsComponentManager::CreateInstance(kXMLDocumentCID, nsnull,                                                   NS_GET_IID(nsIDocument),                                                   getter_AddRefs(doc));  if (NS_FAILED(rv)) return rv;  // XXX This is evil, but we're living in layout, so I'm  // just going to do it.  nsXMLDocument* xmlDoc = (nsXMLDocument*)(doc.get());  // Now we have to synchronously load the binding file.  // Create an XML content sink and a parser.   nsCOMPtr<nsIChannel> channel;  rv = NS_OpenURI(getter_AddRefs(channel), aURI, nsnull);  if (NS_FAILED(rv)) return rv;  // Call StartDocumentLoad  nsCOMPtr<nsIStreamListener> listener;  if (NS_FAILED(rv = xmlDoc->StartDocumentLoad("view", channel,                                                nsnull, nsnull, getter_AddRefs(listener)))) {    NS_ERROR("Failure to init XBL doc prior to load.");    return rv;  }  // Now do a blocking synchronous parse of the file.  nsCOMPtr<nsIInputStream> in;  PRUint32 sourceOffset = 0;  rv = channel->OpenInputStream(0, -1, getter_AddRefs(in));  // If we couldn't open the channel, then just return.  if (NS_FAILED(rv)) return NS_OK;  NS_ASSERTION(in != nsnull, "no input stream");  if (! in) return NS_ERROR_FAILURE;  rv = NS_ERROR_OUT_OF_MEMORY;  nsProxyStream* proxy = new nsProxyStream();  if (! proxy)    return NS_ERROR_FAILURE;  listener->OnStartRequest(channel, nsnull);  while (PR_TRUE) {    char buf[1024];    PRUint32 readCount;    if (NS_FAILED(rv = in->Read(buf, sizeof(buf), &readCount)))        break; // error    if (readCount == 0)        break; // eof    proxy->SetBuffer(buf, readCount);    rv = listener->OnDataAvailable(channel, nsnull, proxy, sourceOffset, readCount);    sourceOffset += readCount;    if (NS_FAILED(rv))        break;  }  listener->OnStopRequest(channel, nsnull, NS_OK, nsnull);  // don't leak proxy!  proxy->Close();  delete proxy;  // The document is parsed. We now have a prototype document.  // Everything worked, so we can just hand this back now.  *aResult = doc;  NS_IF_ADDREF(*aResult);  // The XML content sink produces a ridiculous # of content nodes.  // It generates text nodes even for whitespace.  The following  // call walks the generated document tree and trims out these  // nodes.  nsCOMPtr<nsIContent> root = getter_AddRefs(doc->GetRootContent());  if (root)    StripWhitespaceNodes(root);  return NS_OK;}