if (doc == nsnull)
if (!doc)
NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,                  const nsAReadableString& aNamespaceURI,                   const nsAReadableString& aQualifiedName,                   nsIDOMDocumentType* aDoctype,                  nsIURI* aBaseURI){  nsresult rv;  *aInstancePtrResult = nsnull;  nsXMLDocument* doc = new nsXMLDocument();  if (doc == nsnull)    return NS_ERROR_OUT_OF_MEMORY;  nsCOMPtr<nsIDOMDocument> kungFuDeathGrip(doc);  rv = doc->Reset(nsnull, nsnull);  NS_ENSURE_SUCCESS(rv, rv);  doc->SetDocumentURL(aBaseURI);  doc->SetBaseURL(aBaseURI);  if (aDoctype) {    nsCOMPtr<nsIDOMNode> tmpNode;    rv = doc->AppendChild(aDoctype, getter_AddRefs(tmpNode));    NS_ENSURE_SUCCESS(rv, rv);  }    if (!aQualifiedName.IsEmpty()) {    nsCOMPtr<nsIDOMElement> root;    rv = doc->CreateElementNS(aNamespaceURI, aQualifiedName,                              getter_AddRefs(root));    NS_ENSURE_SUCCESS(rv, rv);    nsCOMPtr<nsIDOMNode> tmpNode;    rv = doc->AppendChild(root, getter_AddRefs(tmpNode));    NS_ENSURE_SUCCESS(rv, rv);  }  *aInstancePtrResult = doc;  NS_ADDREF(*aInstancePtrResult);  return NS_OK;}