You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by "Sharma, Gaurav" <Ga...@Safenet-inc.com> on 2010/04/16 08:55:59 UTC

Validation against schema buffer

Hi All,



Can anyone provide an example of how validation can be performed against schema loaded in any string buffer. I have tried various optiona but I am not getting any success.

What I am trying to do is:



fstream in("my.xsd");



string s, line;

while(getline(in, line))

      s += line;



XMLPlatformUtils::Initialize ();

MemoryManager* mm = new MemoryManagerImpl();

XMLGrammarPool* gp = new XMLGrammarPoolImpl(mm);



XercesDOMParser* parser = NULL;



parser = new XercesDOMParser(0, XMLPlatformUtils::fgMemoryManager, gp);

parser->setCreateCommentNodes(false);

parser->setDoNamespaces(true);

parser->setValidationScheme(XercesDOMParser::Val_Always);

parser->setDoSchema(true);

parser->setValidationSchemaFullChecking(true);

parser->setIncludeIgnorableWhitespace(false);

parser->cacheGrammarFromParse(true);

parser->useCachedGrammarInParse(true);

parser->setLoadSchema(true);

parser->setHandleMultipleImports(true);



MemBufInputSource mem_buf((XMLByte*)s.c_str(),

                              strlen(s.c_str()),

                              "fake_buf",

                               false);







if(!parser->loadGrammar(mem_buf, Grammar::SchemaGrammarType, true)) // Grammer loads without error

      return -1;



delete parser;


parser = new XercesDOMParser(0, XMLPlatformUtils::fgMemoryManager, gp);
parser->setCreateCommentNodes(false);
parser->setDoNamespaces(true);
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
parser->setIncludeIgnorableWhitespace(false);
parser->cacheGrammarFromParse(true);
parser->useCachedGrammarInParse(true);
parser->setLoadSchema(true);

parser->setHandleMultipleImports(true);


parser->parse("my_xml.xml");     // Here parsing fails

if(parser->getErrorCount() > 0)

      return -1;



Kindly suggest me what am I doing wrong.



With Best Regards

Gaurav Sharma







The information contained in this electronic mail transmission 
may be privileged and confidential, and therefore, protected 
from disclosure. If you have received this communication in 
error, please notify us immediately by replying to this 
message and deleting it from your computer without copying 
or disclosing it.