18 #include "precompiled.h"
26 #include <libxml/relaxng.h>
44 xmlRelaxNGParserCtxtPtr ctxt = xmlRelaxNGNewMemParserCtxt(grammar.c_str(), (int)grammar.size());
46 xmlRelaxNGFreeParserCtxt(ctxt);
49 LOGERROR(L
"RelaxNGValidator: Failed to compile schema");
75 shared_ptr<RelaxNGSchema> schema;
79 std::map<std::string, shared_ptr<RelaxNGSchema> >::iterator it =
g_SchemaCache.find(grammar);
82 schema = shared_ptr<RelaxNGSchema>(
new RelaxNGSchema(grammar));
100 std::string docutf8 =
"<?xml version='1.0' encoding='utf-8'?>" +
utf8_from_wstring(document);
111 LOGERROR(L
"RelaxNGValidator: No grammar loaded");
115 xmlDocPtr doc = xmlReadMemory(document.c_str(), (int)document.size(),
utf8_from_wstring(filename).c_str(), NULL, XML_PARSE_NONET);
118 LOGERROR(L
"RelaxNGValidator: Failed to parse document");
122 xmlRelaxNGValidCtxtPtr ctxt = xmlRelaxNGNewValidCtxt(
m_Schema);
123 int ret = xmlRelaxNGValidateDoc(ctxt, doc);
124 xmlRelaxNGFreeValidCtxt(ctxt);
133 LOGERROR(L
"RelaxNGValidator: Validation failed");
138 LOGERROR(L
"RelaxNGValidator: Internal error %d", ret);
std::string utf8_from_wstring(const std::wstring &src, Status *err)
opposite of wstring_from_utf8
Locks a CMutex over this object's lifetime.
static std::map< std::string, shared_ptr< RelaxNGSchema > > g_SchemaCache
A non-recursive mutual exclusion lock.
#define TIMER_ACCRUE(client)
Measure the time taken to execute code up until end of the current scope; bill it to the given TimerC...
RelaxNGSchema(const std::string &grammar)
bool Validate(const std::wstring &filename, const std::wstring &document)
xmlRelaxNG * xmlRelaxNGPtr
static CMutex g_SchemaCacheLock
#define TIMER_ADD_CLIENT(id)
"allocate" a new TimerClient that will keep track of the total time billed to it, along with a descri...
bool LoadGrammar(const std::string &grammar)
bool ValidateEncoded(const std::wstring &filename, const std::string &document)