validate xml against xsd using xerces C++ lib

Discussion in 'XML' started by naivexml, May 16, 2011.

  1. naivexml

    naivexml

    Joined:
    May 16, 2011
    Messages:
    3
    Hi Guys,

    I have a problem where i want to validate my xml file against xsd both located at my current working directory. Please have t look to the code snippet below:

    XercesDOMParser *domParser = new XercesDOMParser;
    LocalFileInputSource fin(X("./sample.xsd"));

    domParser->setExternalSchemaLocation(X("./sample.xsd"));

    Grammar *gmr = domParser->loadGrammar(fin, Grammar::SchemaGrammarType);

    if (gmr == NULL)
    {
    cerr << "couldn't load schema" << endl;
    //return false;
    }

    ParserErrorHandler errorHandler; //Derived from SetErrorhandler Class

    domParser->setErrorHandler(&errorHandler);
    domParser->setValidationScheme(XercesDOMParser::Val_Auto);
    domParser->setDoNamespaces(true);
    domParser->setDoSchema(true);
    domParser->setValidationConstraintFatal(true);


    domParser->parse("./sample.xml");
    cerr << domParser->getErrorCount() << endl;
    if (domParser->getErrorCount() == 0)
    cerr << "XML file validated against the schema successfully" << endl;
    else
    cerr << "XML file doesn't conform to the schema" << endl;

    when I try to execute above code, i get "couldn't load schema" error message.
    I am not getting the exact point of problem here, Is this the way we use DOM Parser to validate xml?
    Seems that you have already implemented this logic, please help me in getting out of this error.
    It's urgent. Please reply guys.
    Thanks a lot in advance.
     
    Last edited: May 16, 2011
    naivexml, May 16, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jens M. Felderhoff

    Re: validate xml against xsd, xerces

    Jens M. Felderhoff, Jul 11, 2003, in forum: XML
    Replies:
    0
    Views:
    2,529
    Jens M. Felderhoff
    Jul 11, 2003
  2. jacksuyu@gmail.com

    how to validate XML against one given xsd file

    jacksuyu@gmail.com, Feb 4, 2005, in forum: XML
    Replies:
    2
    Views:
    759
    jacksuyu@gmail.com
    Feb 15, 2005
  3. Rushi
    Replies:
    3
    Views:
    866
    Rushi
    Dec 9, 2005
  4. ric_deez
    Replies:
    0
    Views:
    1,109
    ric_deez
    Apr 3, 2006
  5. christian.eickhoff@nt.uni-saarland.de

    Validation of XML file against external XSD Schema using Xerces CDT

    christian.eickhoff@nt.uni-saarland.de, Oct 11, 2006, in forum: XML
    Replies:
    8
    Views:
    1,798
    naivexml
    May 16, 2011
Loading...

Share This Page