17#ifdef STORM_HAVE_XERCES
20 xercesc::XMLPlatformUtils::Initialize();
21 }
catch (xercesc::XMLException
const&) {
23 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Failed to initialize xercesc.");
26 auto parser =
new xercesc::XercesDOMParser();
27 parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
28 parser->setDoNamespaces(
false);
29 parser->setDoSchema(
false);
30 parser->setLoadExternalDTD(
false);
31 parser->setIncludeIgnorableWhitespace(
false);
33 auto errHandler = (xercesc::ErrorHandler*)
new xercesc::HandlerBase();
34 parser->setErrorHandler(errHandler);
38 parser->parse(filename.c_str());
39 }
catch (xercesc::XMLException
const& toCatch) {
40 auto message = xercesc::XMLString::transcode(toCatch.getMessage());
43 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException, message);
44 xercesc::XMLString::release(&message);
45 }
catch (
const xercesc::DOMException& toCatch) {
46 auto message = xercesc::XMLString::transcode(toCatch.msg);
49 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException, message);
50 xercesc::XMLString::release(&message);
54 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Failed to parse pnml file.\n");
58 parser->getDocument()->normalizeDocument();
59 xercesc::DOMElement* elementRoot =
parser->getDocument()->getDocumentElement();
61 if (storm::adapters::XMLtoString(elementRoot->getTagName()) ==
"pnml") {
62 STORM_LOG_WARN_COND(constantDefinitions ==
"",
"Constant definitions for pnml files are currently not supported.");
64 return p.parse(elementRoot);
65 }
else if (storm::adapters::XMLtoString(elementRoot->getTagName()) ==
"project") {
66 GreatSpnEditorProjectParser p(constantDefinitions);
67 return p.parse(elementRoot);
70 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Failed to identify the root element.\n");
76 xercesc::XMLPlatformUtils::Terminate();
78 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is not compiled with XML support: " << filename <<
" can not be parsed.");