if (APP_DEBUG)  printf("Upcast to nsIDocumentViewer failed\n");
PRINTF("Upcast to nsIDocumentViewer failed\n");
FindNamedXULElement(nsIDocShell * aShell,                              const char *aId,                              nsCOMPtr<nsIDOMElement> * aResult ) {    nsresult rv = NS_OK;    nsCOMPtr<nsIContentViewer> cv;    rv = aShell ? aShell->GetContentViewer(getter_AddRefs(cv))               : NS_ERROR_NULL_POINTER;    if ( cv ) {        // Up-cast.        nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));        if ( docv ) {            // Get the document from the doc viewer.            nsCOMPtr<nsIDocument> doc;            rv = docv->GetDocument(*getter_AddRefs(doc));            if ( doc ) {                // Up-cast.                nsCOMPtr<nsIDOMXULDocument> xulDoc( do_QueryInterface(doc) );                  if ( xulDoc ) {                    // Find specified element.                    nsCOMPtr<nsIDOMElement> elem;                    rv = xulDoc->GetElementById( NS_ConvertASCIItoUCS2(aId), getter_AddRefs(elem) );                    if ( elem ) {      *aResult =  elem;                    } else {                       if (APP_DEBUG) printf("GetElementByID failed, rv=0x%X\n",(int)rv);                    }                } else {                  if (APP_DEBUG)   printf("Upcast to nsIDOMXULDocument failed\n");                }            } else {               if (APP_DEBUG)  printf("GetDocument failed, rv=0x%X\n",(int)rv);            }        } else {             if (APP_DEBUG)  printf("Upcast to nsIDocumentViewer failed\n");        }    } else {       if (APP_DEBUG) printf("GetContentViewer failed, rv=0x%X\n",(int)rv);    }    return rv;}