6 #include <xercesc/util/PlatformUtils.hpp>
7 #include <xercesc/util/OutOfMemoryException.hpp>
8 #include <xercesc/dom/DOMException.hpp>
9 #include <xercesc/dom/DOMImplementation.hpp>
10 #include <xercesc/dom/DOMNamedNodeMap.hpp>
11 #include <xercesc/sax/SAXParseException.hpp>
16 using XERCES_CPP_NAMESPACE::XercesDOMParser;
17 using XERCES_CPP_NAMESPACE::XMLPlatformUtils;
18 using XERCES_CPP_NAMESPACE::XMLException;
19 using XERCES_CPP_NAMESPACE::OutOfMemoryException;
20 using XERCES_CPP_NAMESPACE::DOMException;
21 using XERCES_CPP_NAMESPACE::DOMImplementation;
32 static XercesDOMParser::ValSchemes ValScheme = XercesDOMParser::Val_Auto;
33 bool bDoNamespaces =
false;
34 bool bDoSchema =
false;
35 bool bSchemaFullChecking =
false;
36 bool bDoCreate =
false;
41 XMLPlatformUtils::Initialize();
43 catch(
const XMLException &toCatch)
45 cerr <<
"Error during Xerces-c Initialization.\n"
46 <<
" Exception message:"
54 parserPtr =
new XercesDOMParser;
55 parserPtr->setValidationScheme(ValScheme);
56 parserPtr->setDoNamespaces(bDoNamespaces);
57 parserPtr->setDoSchema(bDoSchema);
58 parserPtr->setValidationSchemaFullChecking(bSchemaFullChecking);
59 parserPtr->setCreateEntityReferenceNodes(bDoCreate);
64 parserPtr->setErrorHandler(errorHPtr);
70 parserPtr->parse(fileName.c_str());
72 catch (
const OutOfMemoryException&)
74 cerr <<
"OutOfMemoryException" << endl;
78 catch (
const XMLException& e)
80 cerr <<
"An error occurred during parsing\n Message: "
85 catch (
const DOMException& e)
87 const unsigned int maxChars = 2047;
88 XMLCh errText[maxChars + 1];
90 cerr <<
"\nDOM Error during parsing: '" << fileName <<
"'\n"
91 <<
"DOMException code is: " << e.code << endl;
92 if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
93 cerr <<
"Message is: " <<
TempCString(errText) << endl;
99 cerr <<
"An error occurred during parsing\n " << endl;
120 documentPtr = parserPtr->getDocument();
131 XMLPlatformUtils::Terminate();
137 const char itemName[],
float* valuePtr)
146 const char itemName[],
string* valuePtr)
148 (*valuePtr) = TempCString(nodePtr->getNamedItem(XercesString(itemName))->getNodeValue());
154 const char itemName[],
bool* valuePtr)
162 return (strcmp(cString,other) == 0);
167 istringstream inputStream;
169 inputStream.str(cString);
170 inputStream >> (*valuePtr);
171 return inputStream.good();
177 istringstream inputStream;
179 inputStream.str(cString);
180 inputStream >> (*valuePtr);
181 return inputStream.good();
186 string value(cString);
187 if ((value ==
"true") || (value ==
"1"))
192 if ((value ==
"false") || (value ==
"0"))
212 cerr <<
"\nError at file " <<
TempCString(e.getSystemId())
213 <<
", line " << e.getLineNumber()
214 <<
", char " << e.getColumnNumber()
215 <<
"\n Message: " <<
TempCString(e.getMessage()) << endl;
221 cerr <<
"\nFatal Error at file " <<
TempCString(e.getSystemId())
222 <<
", line " << e.getLineNumber()
223 <<
", char " << e.getColumnNumber()
224 <<
"\n Message: " <<
TempCString(e.getMessage()) << endl;
229 cerr <<
"\nWarning at file '" <<
TempCString(e.getSystemId())
230 <<
"', line " << e.getLineNumber()
231 <<
", char " << e.getColumnNumber()
232 <<
"\n Message: " <<
TempCString(e.getMessage()) << endl;
void warning(const XERCES_CPP_NAMESPACE::SAXParseException &e)
Header file for V-ART class "XmlBase".
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException &e)
XmlBase()
Creates an unitialized object.
void error(const XERCES_CPP_NAMESPACE::SAXParseException &e)
static bool GetAttributeValue(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *nodePtr, const char itemName[], float *valuePtr)
Gets an item value for certain node.
void Terminate()
Terminates Xerces objects.
Class for auto conversion from C strings to Xerces strings.
bool ParseFile(const std::string &fileName)
Checks if the file comforms to DTD.
bool getSawErrors() const
bool operator==(const char *other) const
Check against a C string.
bool GetValue(int *valuePtr) const
Class for auto conversion from Xerces strings to C strings.
Provides pretty errors messages for Xerces.