16#ifdef STORM_HAVE_XERCES
19 xercesc::XMLPlatformUtils::Initialize();
20 }
catch (xercesc::XMLException
const& toCatch) {
22 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Failed to initialize xercesc\n");
25 auto parser =
new xercesc::XercesDOMParser();
26 parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
27 parser->setDoNamespaces(
false);
28 parser->setDoSchema(
false);
29 parser->setLoadExternalDTD(
false);
30 parser->setIncludeIgnorableWhitespace(
false);
32 auto errHandler = (xercesc::ErrorHandler*)
new xercesc::HandlerBase();
33 parser->setErrorHandler(errHandler);
37 parser->parse(filename.c_str());
38 }
catch (xercesc::XMLException
const& toCatch) {
39 auto message = xercesc::XMLString::transcode(toCatch.getMessage());
42 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException, message);
43 xercesc::XMLString::release(&message);
44 }
catch (
const xercesc::DOMException& toCatch) {
45 auto message = xercesc::XMLString::transcode(toCatch.msg);
48 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException, message);
49 xercesc::XMLString::release(&message);
53 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Failed to parse pnml file.\n");
57 parser->getDocument()->normalizeDocument();
58 xercesc::DOMElement* elementRoot = parser->getDocument()->getDocumentElement();
60 if (storm::adapters::XMLtoString(elementRoot->getTagName()) ==
"pnml") {
61 STORM_LOG_WARN_COND(constantDefinitions ==
"",
"Constant definitions for pnml files are currently not supported.");
63 return p.parse(elementRoot);
64 }
else if (storm::adapters::XMLtoString(elementRoot->getTagName()) ==
"project") {
65 GreatSpnEditorProjectParser p(constantDefinitions);
66 return p.parse(elementRoot);
69 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Failed to identify the root element.\n");
75 xercesc::XMLPlatformUtils::Terminate();
77 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Storm is not compiled with XML support: " << filename <<
" can not be parsed");