Hi All,
i m using the following code for validation but it terminates with this message---
"terminate called after throwing an instance of 'xercesc_2_7::DOMException'
Aborted"
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/parsers/AbstractDOMParser.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMImplementationRegistry.hpp>
#include <xercesc/dom/DOMBuilder.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMError.hpp>
#include <xercesc/dom/DOMLocator.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/dom/DOMAttr.hpp>
#include <string.h>
#include <stdlib.h>
#include <xercesc/dom/DOMErrorHandler.hpp>
#include <xercesc/util/XMLString.hpp>
#include "DOMCount.hpp" //for my error handlers
#if defined(XERCES_NEW_IOSTREAMS)
#include <iostream>
#else
#include <iostream.h>
#endif
XERCES_CPP_NAMESPACE_USE
int main(int argc, char* argv[])
{
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
//strGeneralResult.Format(_T("Error during Xerces initialization! :\n%s\n"), toCatch.getMessage());
return -1;
}
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(gL S);
DOMBuilder* parser = ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHR ONOUS, 0);
parser->setFeature(XMLUni::fgDOMNamespaces, true);
parser->setFeature(XMLUni::fgXercesSchema, true);
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
parser->setFeature(XMLUni::fgDOMValidation, true);
// enable datatype normalization - default is off
parser->setFeature(XMLUni::fgDOMDatatypeNormalization, true);
XMLCh* propertyValue = XMLString::transcode(argv[1]);
parser->setFeature(XMLUni::fgXercesSchemaExternalNoNameSp aceSchemaLocation,propertyValue);
// And create our error handler and install it
// CMyDOMErrorHandler must be derived from DOMErrorHandler
DOMCountErrorHandler* errorHandler;
parser->setErrorHandler(errorHandler);
//
// Get the starting time and kick off the parse of the indicated
// file. Catch any exceptions that might propogate out of it.
//
unsigned long duration;
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc = 0;
try
{
// reset document pool
parser->resetDocumentPool();
char* filename = argv[2];
doc = parser->parseURI(filename);
}
catch (const XMLException& toCatch)
{
XERCES_STD_QUALIFIER cout<<"\nhere1\n";
//strGeneralResult.Format(_T("Error during parsing: %s\nXMLException message is:\n %s\n"), strXMLFile, toCatch.getMessage());
}
catch (const DOMException& toCatch)
{
XERCES_STD_QUALIFIER cout<<"\nhere2\n";
const unsigned int maxChars = 2047;
XMLCh errText[maxChars + 1];
//strGeneralResult.Format(_T("DOM Error during parsing:%s\nDOMException code is: %d\n"), strXMLFile, toCatch.code);
if (DOMImplementation::loadDOMExceptionMsg(toCatch.co de,errText, maxChars))
{
//CString strDOMExc;
//strDOMExc.Format(_T("\nMessage is: %s"), errText);
//strGeneralResult +=strDOMExc;
}
}
catch (...)
{
XERCES_STD_QUALIFIER cout<<"\nhere3\n";
//strGeneralResult.Format(_T("Unexpected exception during parsing: %s\n"), strXMLFile);
}
XMLPlatformUtils::Terminate();
return 0;
}
i saw some postings here regarding validation and tried to use those codes but still its not working for me :(
Any help to resolve this issue is highly appreciated.
Thanks in advance
dees