27 #include "../common/Translator.h"
33 #include <xercesc/parsers/XercesDOMParser.hpp>
34 #include <xercesc/sax/SAXException.hpp>
35 #include <xercesc/sax2/XMLReaderFactory.hpp>
36 #include <xercesc/util/XMLException.hpp>
43 const bool doNamespace,
47 assert(xmlFile.empty() ==
false);
49 std::auto_ptr<xercesc::XercesDOMParser> parser(
new xercesc::XercesDOMParser());
50 std::auto_ptr<ErrorHandler> errHandler(
new ErrorHandler);
51 parser->setErrorHandler(errHandler.get());
53 xercesc::XercesDOMParser::ValSchemes valScheme = valid ? xercesc::XercesDOMParser::Val_Always : xercesc::XercesDOMParser::Val_Never;
57 parser->setDoNamespaces(doNamespace);
58 parser->setDoSchema(doSchema);
59 parser->setValidationScheme(valScheme);
60 parser->cacheGrammarFromParse(
true);
65 parser->parse(xmlFile.c_str());
67 catch(
const xercesc::SAXException& e)
69 std::string m =
TE_TR(
"Could not read the XML file: ");
71 m +=
TE_TR(
", due to the following error: ");
76 catch(
const xercesc::DOMException& e)
78 std::string m =
TE_TR(
"Could not read the XML file: ");
80 m +=
TE_TR(
", due to the following error: ");
85 catch(
const xercesc::XMLException& e)
87 std::string m =
TE_TR(
"Could not read the XML file: ");
89 m +=
TE_TR(
", due to the following error: ");
95 if(parser->getErrorCount() > 0)
97 std::string m =
TE_TR(
"Could not read the XML file: ");
99 m +=
", due to the following problem: ";
100 m += errHandler->getErrors();
106 xercesc::DOMDocument* doc = parser->adoptDocument();
109 throw Exception(
TE_TR(
"Unable to read the XML document!"));
This class implements Xerces interface for error handlers.
#define TE_TR(message)
It marks a string in order to get translated.
TEXERCESEXPORT xercesc::DOMDocument * readXML(const std::string &xmlFile, const bool doNamespace=false, const bool doSchema=false, const bool valid=false)
It reads the XML file using the DOM API.
An exception class for the xerces module.
This class implements Xerces interface for error handlers.
std::string ToString(const XMLCh *const value)
It converts the XML string to a standard C++ string.