rv = htmlElement->AppendChildTo(headElement, PR_FALSE);
rv = htmlElement->AppendChildTo(headElement, PR_FALSE, PR_FALSE);
nsresult DocumentViewerImpl::GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, nsIDocument ** aNewDoc){  //NS_ENSURE_ARG_POINTER(*aDevSpec);  NS_ENSURE_ARG_POINTER(aNewDoc);    // create document  nsCOMPtr<nsIDocument> doc;  nsresult rv = NS_NewHTMLDocument(getter_AddRefs(doc));  if (NS_FAILED(rv)) { return rv; }  if (!doc) { return NS_ERROR_NULL_POINTER; }  nsCOMPtr<nsINodeInfoManager> nimgr;  rv = doc->GetNodeInfoManager(*getter_AddRefs(nimgr));  NS_ENSURE_SUCCESS(rv, rv);  nsCOMPtr<nsINodeInfo> nodeInfo;  nimgr->GetNodeInfo(nsHTMLAtoms::html, nsnull, kNameSpaceID_None,                     *getter_AddRefs(nodeInfo));  // create document content  nsCOMPtr<nsIHTMLContent> htmlElement;  nsCOMPtr<nsIHTMLContent> headElement;  nsCOMPtr<nsIHTMLContent> bodyElement;    // create the root  rv = NS_NewHTMLHtmlElement(getter_AddRefs(htmlElement), nodeInfo);  if (NS_FAILED(rv)) { return rv; }  if (!htmlElement) { return NS_ERROR_NULL_POINTER; }    // create the head  nimgr->GetNodeInfo(NS_ConvertASCIItoUCS2("head"), nsnull,                     kNameSpaceID_None, *getter_AddRefs(nodeInfo));  rv = NS_NewHTMLHeadElement(getter_AddRefs(headElement), nodeInfo);  if (NS_FAILED(rv)) { return rv; }  if (!headElement) { return NS_ERROR_NULL_POINTER; }  headElement->SetDocument(doc, PR_FALSE, PR_TRUE);    // create the body  nimgr->GetNodeInfo(nsHTMLAtoms::body, nsnull, kNameSpaceID_None,                    *getter_AddRefs(nodeInfo));  rv = NS_NewHTMLBodyElement(getter_AddRefs(bodyElement), nodeInfo);  if (NS_FAILED(rv)) { return rv; }  if (!bodyElement) { return NS_ERROR_NULL_POINTER; }  bodyElement->SetDocument(doc, PR_FALSE, PR_TRUE);    // put the head and body into the root  rv = htmlElement->AppendChildTo(headElement, PR_FALSE);  if (NS_FAILED(rv)) { return rv; }  rv = htmlElement->AppendChildTo(bodyElement, PR_FALSE);  if (NS_FAILED(rv)) { return rv; }    // load the document into the docshell  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(doc);  if (!domDoc) { return NS_ERROR_NULL_POINTER; }  nsCOMPtr<nsIDOMElement> htmlDOMElement = do_QueryInterface(htmlElement);  if (!htmlDOMElement) { return NS_ERROR_NULL_POINTER; }  //nsCOMPtr<nsIContent> rootContent(do_QueryInterface(htmlElement));  //doc->SetRootContent(rootContent);  *aNewDoc = doc.get();  NS_ADDREF(*aNewDoc);  return rv;}