I don't set any options.
I have a class which inherits from DOMErrorHandler, I only set the error
handler to a class of this type.
I cut and paste the related section from my classes to a main function and a
few functions.
here is the code snippet:
// Test_Fcs.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "Test_Fcs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMError.hpp>
#include <xercesc/dom/DOMErrorHandler.hpp>
#include <xercesc/dom/DOMLocator.hpp>
#include <xercesc/util/XMLString.hpp>
CWinApp theApp;
using namespace std;
class FcsException {
public:
FcsException();
~FcsException();
CString m_csErrMsg;
};
class FcsDomErrHand : public DOMErrorHandler {
public:
FcsDomErrHand();
~FcsDomErrHand();
bool handleError(const DOMError& domError);
void resetErrors();
bool m_fErr;
CString m_csSeverity;
int m_nLineNum;
int m_nColNum;
CString m_csDOMErr;
CString m_csFcsMsg;
};
FcsException::FcsException() {
}
FcsException::~FcsException() {
}
FcsDomErrHand::FcsDomErrHand() {
m_fErr = false;
m_csSeverity.Empty();
m_nLineNum = -1;
m_nColNum = -1;
m_csDOMErr.Empty();
m_csFcsMsg.Empty();
}
FcsDomErrHand::~FcsDomErrHand() {
}
bool FcsDomErrHand::handleError(const DOMError &domError) {
m_fErr = true;
if (domError.getSeverity() == DOMError::DOM_SEVERITY_WARNING)
m_csSeverity.Format("DOM_SEVERITY_WARNING");
else if (domError.getSeverity() == DOMError::DOM_SEVERITY_ERROR)
m_csSeverity.Format("DOM_SEVERITY_ERROR");
else
m_csSeverity.Format("DOM_SEVERITY_CRITICAL");
if ((m_nLineNum = domError.getLocation()->getLineNumber())==-1) {
m_csFcsMsg.Format("[ERROR] FcsDomErrHand::handleError:
Cannot retrieve Line Number of error");
return false;
}
if ((m_nColNum = domError.getLocation()->getColumnNumber())==-1) {
m_csFcsMsg.Format("[ERROR] FcsDomErrHand::handleError:
Cannot retrieve Column Number of error. %s", m_csFcsMsg);
return false;
}
m_csDOMErr.Format("%s",XMLString::transcode(domError.getMessage()));
if (m_csDOMErr.IsEmpty()) {
m_csFcsMsg.Format("[ERROR] FcsDomErrHand::handleError:
Cannot retrieve dom error message. %s", m_csFcsMsg);
return false;
}
m_csFcsMsg.Format("[ERROR] FcsDomErrHand::handleError: Caught dom
error in parser. Severity: %s. Line Number: %d. Column Number: %d. Error
Message %s",m_csSeverity,m_nLineNum,m_nColNum,m_csDOMErr);
return true;
}
void FcsDomErrHand::resetErrors() {
m_fErr = false;
}
CString GetRequestXml() {
FILE* pFl=NULL;
char* pszRequestFl="f:/rog/testdata/request.xml"; //change
int nRead=-1,nBufSize;
char szXml[1024];
bool fEOF = false;
CString csXML;
if ((pFl = fopen(pszRequestFl,"r")) == NULL)
return "ERR";
while (!fEOF) {
nRead = -1;
memset(szXml,'\0',sizeof(szXml));
if ((nRead =
fread(szXml,sizeof(char),sizeof(szXml)-1,pFl))==-1)
return "ERR";
if ((nBufSize = strlen(szXml)) < sizeof(szXml)-1)
fEOF = TRUE;
csXML += szXml;
}
fclose(pFl);
return csXML;
}
bool SetResponseXml(CString csXml) {
FILE* pFl=NULL;
char* pszResponseFl="f:/rog/testdata/response.xml";
int nWrtn=-1;
if ((pFl = fopen(pszResponseFl,"w")) == NULL)
return false;
if
((nWrtn=fwrite(csXml.GetBuffer(csXml.GetLength()),sizeof(char),csXml.GetLeng
th(),pFl))==-1)
return false;
fclose(pFl);
return true;
}
void TestParser() {
CString csXml = GetRequestXml();
FcsException* m_pFcsExc=NULL;
m_pFcsExc = new FcsException();
DOMDocument* m_pRequestDomDoc=NULL;
DOMImplementation* m_pImpl;
DOMBuilder* m_pBuild;
try {
XMLPlatformUtils::Initialize();
}
catch(XMLException &E) {
m_pFcsExc->m_csErrMsg.Format("[ERROR] FcsDom::InitLib.
XMLPlatformUtils::Initialize failed.
%s",XMLString::transcode(E.getMessage()));
throw *m_pFcsExc;
}
m_pRequestDomDoc=NULL;
if ((m_pImpl =
DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core")
))==NULL) {
m_pFcsExc->m_csErrMsg.Format("[ERROR] FcsDom::Parse:
DOMImplementationRegistry::getDOMImplementation failed.");
throw *m_pFcsExc;
}
if ((m_pBuild =
((DOMImplementationLS*)m_pImpl)->createDOMBuilder(DOMImplementationLS::MODE_
SYNCHRONOUS, 0))==NULL) {
m_pFcsExc->m_csErrMsg.Format("[ERROR] FcsDom::Parse:
createDOMBuilder failed.");
throw *m_pFcsExc;
}
FcsDomErrHand errHand;
m_pBuild->setErrorHandler(&errHand);
//what other options should I set here?
try {
m_pRequestDomDoc =
m_pBuild->parseURI(XMLString::transcode(csXml));
}
catch (XMLException &E) {
m_pFcsExc->m_csErrMsg.Format("[ERROR] FcsDomDoc::Parse:
DOMBuilder.parseURI failed. %s",XMLString::transcode(E.getMessage()));
throw *m_pFcsExc;
}
catch (DOMException &E) {
m_pFcsExc->m_csErrMsg.Format("[ERROR] FcsDomDoc::Parse:
DOMBuilder.parseURI failed. %s",XMLString::transcode(E.msg));
throw *m_pFcsExc;
}
catch (...) {
m_pFcsExc->m_csErrMsg.Format("FcsDomDoc::Parse: [ERROR]
DOMBuilder.parseURI failed. Unknown Error");
throw *m_pFcsExc;
}
if (errHand.m_fErr) {
m_pFcsExc->m_csErrMsg.Format("%s",errHand.m_csFcsMsg);
throw *m_pFcsExc;
}
if (m_pRequestDomDoc == NULL) {
m_pFcsExc->m_csErrMsg.Format("[ERROR] FcsDomDoc::Parse:
DOMBuilder.parseURI failed. Unknown Error");
throw *m_pFcsExc;
}
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(),
0)) {
printf("Fatal Error: MFC initialization failed\n");
return 1;
}
try {
TestParser();
}
catch (FcsException E) {
CString csErr = E.m_csErrMsg;
printf("%s\n",csErr.GetBuffer(csErr.GetLength()));
}
return 0;
}
-----Original Message-----
From: Gareth Reakes [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 06, 2003 1:31 PM
To: '[EMAIL PROTECTED]'
Subject: Re: The primary document entity could not be opened
Hi,
post a snippet of you code from where you create your parser and
set the options.
Gareth
On Thu, 6 Mar 2003, Williams, Rodger wrote:
> I catch following error, in a try&catch statement, on parsing a
> string(pulled from a text file) to construct a xerces document:
> "An exception occured! Type:RuntimeException, Message:The primary
> document entity could not be opened.
Id=E:\dev\prgm102\<request><\request>"
> Langauge: VC++ 6.0
> Xerces Version: Xerces-C++ Version 2.1.0
> Platform, W2K Serv
>
> When I open the xml text source file in the browser, its valid.
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Gareth Reakes, Head of Product Development +44-1865-203192
DecisionSoft Limited http://www.decisionsoft.com
XML Development and Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]