nsresult txParseDocumentFromURI(const nsAString& aHref, const txXPathNode& aLoader, nsAString& aErrMsg, txXPathNode** aResult) { NS_ENSURE_ARG_POINTER(aResult); *aResult = nsnull; #ifndef TX_EXE nsCOMPtr<nsIURI> documentURI; nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref); NS_ENSURE_SUCCESS(rv, rv); nsIDocument* loaderDocument = txXPathNativeNode::getDocument(aLoader); nsCOMPtr<nsILoadGroup> loadGroup = loaderDocument->GetDocumentLoadGroup(); // For the system principal loaderUri will be null here, which is good // since that means that chrome documents can load any uri. // Raw pointer, we want the resulting txXPathNode to hold a reference to // the document. nsIDOMDocument* theDocument = nsnull; rv = nsSyncLoadService::LoadDocument(documentURI, loaderDocument->NodePrincipal(), loadGroup, PR_TRUE, &theDocument); if (NS_FAILED(rv)) { aErrMsg.Append(NS_LITERAL_STRING("Document load of ") + aHref + NS_LITERAL_STRING(" failed.")); return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE; } *aResult = txXPathNativeNode::createXPathNode(theDocument); if (!*aResult) { NS_RELEASE(theDocument); return NS_ERROR_FAILURE; } return NS_OK; #else istream* xslInput = URIUtils::getInputStream(aHref, aErrMsg); if (!xslInput) { return NS_ERROR_FAILURE; } return txParseFromStream(*xslInput, aHref, aErrMsg, aResult); #endif }
txXPathNode* txStandaloneXSLTProcessor::parsePath(const nsACString& aPath, ErrorObserver& aErr) { NS_ConvertASCIItoUCS2 path(aPath); ifstream xmlInput(PromiseFlatCString(aPath).get(), ios::in); if (!xmlInput) { aErr.receiveError(NS_LITERAL_STRING("Couldn't open ") + path); return 0; } // parse source txXPathNode* xmlDoc; nsAutoString errors; nsresult rv = txParseFromStream(xmlInput, path, errors, &xmlDoc); xmlInput.close(); if (NS_FAILED(rv) || !xmlDoc) { aErr.receiveError(NS_LITERAL_STRING("Parsing error \"") + errors + NS_LITERAL_STRING("\"")); } return xmlDoc; }