| 2049 | } |
| 2050 | |
| 2051 | void ParameterManager::CheckDocument() const |
| 2052 | { |
| 2053 | if (!_pDocument) { |
| 2054 | return; |
| 2055 | } |
| 2056 | |
| 2057 | try { |
| 2058 | // |
| 2059 | // Plug in a format target to receive the resultant |
| 2060 | // XML stream from the serializer. |
| 2061 | // |
| 2062 | // LocalFileFormatTarget prints the resultant XML stream |
| 2063 | // to a file once it receives any thing from the serializer. |
| 2064 | // |
| 2065 | MemBufFormatTarget myFormTarget; |
| 2066 | SaveDocument(&myFormTarget); |
| 2067 | |
| 2068 | // Either use the file saved on disk or write the current XML into a buffer in memory |
| 2069 | // const char* xmlFile = "..."; |
| 2070 | MemBufInputSource xmlFile(myFormTarget.getRawBuffer(), myFormTarget.getLen(), "(memory)"); |
| 2071 | |
| 2072 | // Either load the XSD file from disk or use the built-in string |
| 2073 | // const char* xsdFile = "..."; |
| 2074 | std::string xsdStr(xmlSchemeString); // NOLINT |
| 2075 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) |
| 2076 | MemBufInputSource xsdFile( |
| 2077 | reinterpret_cast<const XMLByte*>(xsdStr.c_str()), |
| 2078 | xsdStr.size(), |
| 2079 | "Parameter.xsd" |
| 2080 | ); |
| 2081 | |
| 2082 | // See |
| 2083 | // http://apache-xml-project.6118.n7.nabble.com/validating-xml-with-xsd-schema-td17515.html |
| 2084 | // |
| 2085 | XercesDOMParser parser; |
| 2086 | Grammar* grammar = parser.loadGrammar(xsdFile, Grammar::SchemaGrammarType, true); |
| 2087 | if (!grammar) { |
| 2088 | Base::Console().error("Grammar file cannot be loaded.\n"); |
| 2089 | return; |
| 2090 | } |
| 2091 | |
| 2092 | parser.setExternalNoNamespaceSchemaLocation("Parameter.xsd"); |
| 2093 | // parser.setExitOnFirstFatalError(true); |
| 2094 | // parser.setValidationConstraintFatal(true); |
| 2095 | parser.cacheGrammarFromParse(true); |
| 2096 | parser.setValidationScheme(XercesDOMParser::Val_Auto); |
| 2097 | parser.setDoNamespaces(true); |
| 2098 | parser.setDoSchema(true); |
| 2099 | parser.setDisableDefaultEntityResolution(true); |
| 2100 | |
| 2101 | DOMTreeErrorReporter errHandler; |
| 2102 | parser.setErrorHandler(&errHandler); |
| 2103 | parser.parse(xmlFile); |
| 2104 | |
| 2105 | if (parser.getErrorCount() > 0) { |
| 2106 | Base::Console().error( |
| 2107 | "Unexpected XML structure detected: %zu errors\n", |
| 2108 | parser.getErrorCount() |