Hello Dave,
Even i'm using a similar piece of code for XML String parsing with
Xerces 2.8 and Visual Studio 2005.
thsi piece of code goes thru fine the first time but the second time onwards
even for a valid XML, the parse() method throws a generic exception.. i.e
catch(...) block despite having XMLException and DOMException catch blocks
Can you point out any mistakes in the code. this was working fine with
Xerces 2.2 and Visual Studio 6.0
XERCES_CPP_NAMESPACE::XercesDOMParser* m_pDOMParser;
m_pDOMParser = new XERCES_CPP_NAMESPACE::XercesDOMParser;
DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter();
errReporter->resetErrors();
m_pDOMParser->setErrorHandler(errReporter);
m_pDOMParser->resetDocumentPool();
CString strSchemaFile;
CString strSchemaFilePath;
BOOL bFuncRet =
SPVRegAcc::GetXMLFilePath(strSchemaFilePath);
strSchemaFile = strSchemaFilePath + _T("\\config\\");
if(FALSE == m_bDBPatching)
{
strSchemaFile += m_XMLSchemaName;
}
else
{
//MOD V5.1.62 get the dbpatch schema
strSchemaFile += _T("SPV_DBPatch_Schema.xsd");
//MOD V5.1.62 changes end
}
TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree()
m_pDOMParser found schema");
// m_pDOMParser->setErrorHandler(m_pDOMErrorHandler);
m_pDOMParser->setExternalNoNamespaceSchemaLocation(strSchemaFile);
//Get all errors
m_pDOMParser->setExitOnFirstFatalError(true);
//All validation errors are fatal.
m_pDOMParser->setValidationConstraintFatal(true);
//Set the validation scheme
m_pDOMParser->setValidationScheme(XERCES_CPP_NAMESPACE::XercesDOMParser::Val_Auto
);
//Set schema validation
m_pDOMParser->setValidationSchemaFullChecking(false);
//Use namespaces and schema
//m_pDOMParser->setDoNamespaces(true);
m_pDOMParser->setDoSchema(true);
//MOD001V5.2:to correct DF1487 change start
m_pDOMParser->setIncludeIgnorableWhitespace(false);
CT2CA pszConvertedAnsiString (m_XMLFileName);
std::string strStd (pszConvertedAnsiString);
const char* pStr = strStd.c_str();
//const TCHAR* pStr = StringToChar(m_XMLFileName);
TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() converted
StringToChar");
MemBufInputSource* memBufIS = new MemBufInputSource(
(const XMLByte *)pStr
,strlen(pStr)
, bufId
, false
);
//memBufIS->setPublicId(bufId);
/*const XMLCh *const chEncoding = _T("UTF-8");
memBufIS->setEncoding(chEncoding);*/
TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() formed
MemBufInputSourceObject Successfully");
m_pDOMParser->setDoNamespaces(false);
TRACE_INFO("Entering CSPVXMLParserWrapper::CreateDOMTree()
SetDoNamespace set to false");
m_pDOMParser->parse(*memBufIS);
TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() Done
parsing");
delete [] pStr;
TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() Done deleting
pStr");
pStr = NULL;
TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() Set pStr to
NULL");
TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() trying to
delete memBUFIS");
delete memBufIS;
TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTree() deleted
memBUFIS");
memBufIS = NULL;
TRACE_INFO("CSPVXMLParserWrapper::CreateDOMTREE() set memBUFIS
to NULL");
in the release we have
delete m_pDOMParser;
m_pDOMParser = 0 ;
m_ppDOMDocument->release();
in a critical section
Please let me know
thanks and regards,
Pranav
On Thu, Dec 11, 2008 at 9:57 AM, <[EMAIL PROTECTED]> wrote:
> Hello,
>
> So initializing and terminating the xerces-c library could result in a
> failure? I do this in our source as well, and I don't think we've ever had
> a problem, but am concerned about whether this could result in a very
> hard-to-find error in the future.
>
> Also, does each module need to call initialize/terminate on the xerces-c
> library? We dynamically load DLLs that use Xerces internally, so any
> guidance would be helpful.
>
> Thanks,
> Nicholas
>
> -----Original Message-----
> From: David Bertoni [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, December 10, 2008 7:42 PM
> To: [email protected]
> Subject: Re: MemBufInputSource Core Dump
>
> [EMAIL PROTECTED] wrote:
> > David , thank you for your suggestion
> >
> > 1. In now I already fix my parse function
> > 2. I found the Xercesc-C doc ,
> > XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate()
> > can use it in after function start and before function end
> > 3. In your suggestion , told me 「Please make sure you're not initializing
> > and terminating Xerces-C ineach thread 」
> > It's mean in multi-thread env only have once Initialize and Terminate
> ?
> Yes. You should initialize the library once before you start processing
> and terminate once when you're done.
>
> The initialization code is not thread-safe, and initializing and
> terminating the library multiple times is very inefficient.
>
> Dave
>
> ---------------------------------------------------------------------
> 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]
>
>