I'm writing a library which takes xml files and parses them. To prevent users from feeding inalid xmls into my application i'm using xerces to validate the xml files via an xsd.
However, i only manages to validate against xsd-files. Theoretically an user could just open this file and mess around with it. That's why i would like my xsd to be hardcoded in my library.
Unfortunately i haven't found a way to do this with XercesC++, yet.
That's how it is working right now...
bool XmlParser::validateXml(std::string a_XsdFilename)
{
xercesc::XercesDOMParser domParser;
if (domParser.loadGrammar(a_XsdFilename.c_str(), xercesc::Grammar::SchemaGrammarType) == NULL)
{
throw Exceptions::Parser::XmlSchemaNotReadableException();
}
XercesParserErrorHandler parserErrorHandler;
domParser.setErrorHandler(&parserErrorHandler);
domParser.setValidationScheme(xercesc::XercesDOMParser::Val_Always);
domParser.setDoNamespaces(true);
domParser.setDoSchema(true);
domParser.setValidationSchemaFullChecking(true);
domParser.parse(m_Filename.c_str());
return (domParser.getErrorCount() == 0);
}
std::string m_Filename
is a member variable holding the path of the xml i validate.
std::string a_XsdFilename
is the path to the xsd i validate against.
XercesParserErrorHandler
inherits from xercesc::ErrorHandler
and does error handling.
How can i replace std::string a_XsdFilename
with something like std::string a_XsdText
?
Where std::string a_XsdText
contains the schema definition itself instead of a path to a file containing the schema definition.