28 #include <libxml/parser.h> 29 #include <libxml/valid.h> 30 #include <libxml/xmlschemas.h> 35 m_xsdData(QByteArray()),
45 m_xsdFile(QStringLiteral(
"")),
67 va_start(args, format);
68 bool ok = vasprintf(&error, format, args) >= 0;
72 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Libxml error: %1").arg(error));
80 xmlSetStructuredErrorFunc(
nullptr,
nullptr);
82 xmlThrDefSetStructuredErrorFunc(
nullptr,
nullptr);
85 xmlSchemaParserCtxtPtr parsercontext =
nullptr;
87 if (!m_xsdFile.isEmpty())
89 parsercontext = xmlSchemaNewParserCtxt(m_xsdFile.toLocal8Bit().constData());
91 else if (!m_xsdData.isEmpty())
93 parsercontext = xmlSchemaNewMemParserCtxt(m_xsdData.constData(), m_xsdData.size());
98 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to create parser context for XSD"));
102 xmlSchemaPtr schema = xmlSchemaParse(parsercontext);
106 xmlSchemaFreeParserCtxt(parsercontext);
107 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to parse XSD"));
111 xmlSchemaValidCtxtPtr validcontext = xmlSchemaNewValidCtxt(schema);
115 xmlSchemaFree(schema);
116 xmlSchemaFreeParserCtxt(parsercontext);
117 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Could not create XSD schema validation context"));
122 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"XSD loaded and validated"));
126 xmlDocPtr xmldocumentptr = xmlParseFile(m_xmlFile.toLocal8Bit().constData());
127 int result = xmlSchemaValidateDoc(validcontext, xmldocumentptr);
132 xmlFreeDoc(xmldocumentptr);
133 xmlSchemaFreeValidCtxt(validcontext);
134 xmlSchemaFree(schema);
135 xmlSchemaFreeParserCtxt(parsercontext);
bool GetSilent(void) const
static void HandleMessage(void *ctx, const char *format,...)
#define LOG(_MASK_, _LEVEL_, _STRING_)
bool Validated(void) const
TorcXmlValidator(const QString &XmlFile, const QString &XSDFile, bool Silent=false)