Xerces-C++ Schema validation

Discussion in 'XML' started by Nuno, Oct 25, 2006.

  1. Nuno

    Nuno Guest

    Hello,

    I'm looking for a way of validating/parsing the xsd file (schema), i
    only been able of validating the xml file with the corresponding
    schema, but what i want is only validate the xsd file, to check if the
    schema is valid.

    I'm using Xerces-C++ and the only thing that i found is a way of
    parsing the xml file with the xml schema like this:

    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
    ...
    parser->loadGrammar(xsdFile.c_str(), Grammar::SchemaGrammarType,
    true);
    parser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);
    parser->parse(xmlFile.c_str());

    But when i try this with only the xsd file
    (ex:parser->parse(xsdFile.c_str());) the parser gives me these errors:
    ERR: Unknown element 'xs:element'
    ERR: Attribute 'ref' is not declared for element 'xs:element'
    ERR: Unknown element 'xs:schema'
    ERR: Attribute '{http://www.w3.org/2000/xmlns/}xs' is not declared for
    element 'xs:schema'
    ERR: Unknown element 'xs:element'
    ERR: Attribute 'name' is not declared

    My question is:
    is there any way in Xerces-C++ to validate one xsd file only, not the
    xml file against it's schema?

    Thanks
    Nuno
    Nuno, Oct 25, 2006
    #1
    1. Advertising

  2. Nuno

    spiff Guest

    Hi Nuno!

    AFAIK Xerces can't do this for you. Using Saxon-SA you can validate the
    schema itself.

    Regards
    spiff

    http://www.spycomponents.com
    ValidatorBuddy - Use Xerces, Saxon or MSXML in XMLSpy


    Nuno schrieb:

    > Hello,
    >
    > I'm looking for a way of validating/parsing the xsd file (schema), i
    > only been able of validating the xml file with the corresponding
    > schema, but what i want is only validate the xsd file, to check if the
    > schema is valid.
    >
    > I'm using Xerces-C++ and the only thing that i found is a way of
    > parsing the xml file with the xml schema like this:
    >
    > SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
    > ...
    > parser->loadGrammar(xsdFile.c_str(), Grammar::SchemaGrammarType,
    > true);
    > parser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);
    > parser->parse(xmlFile.c_str());
    >
    > But when i try this with only the xsd file
    > (ex:parser->parse(xsdFile.c_str());) the parser gives me these errors:
    > ERR: Unknown element 'xs:element'
    > ERR: Attribute 'ref' is not declared for element 'xs:element'
    > ERR: Unknown element 'xs:schema'
    > ERR: Attribute '{http://www.w3.org/2000/xmlns/}xs' is not declared for
    > element 'xs:schema'
    > ERR: Unknown element 'xs:element'
    > ERR: Attribute 'name' is not declared
    >
    > My question is:
    > is there any way in Xerces-C++ to validate one xsd file only, not the
    > xml file against it's schema?
    >
    > Thanks
    > Nuno
    spiff, Oct 25, 2006
    #2
    1. Advertising

  3. Nuno

    naivexml

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

    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 in getting out of this error.
    It's urgent.
    Thanks a lot in advance.
    naivexml, May 16, 2011
    #3
    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. Ole Hedegaard

    Xerces schema validation

    Ole Hedegaard, Nov 25, 2003, in forum: Java
    Replies:
    2
    Views:
    910
    Esmond Pitt
    Nov 26, 2003
  2. Markus
    Replies:
    1
    Views:
    1,497
    Markus
    Nov 23, 2005
  3. Ole Hedegaard

    Xerces schema validation

    Ole Hedegaard, Nov 25, 2003, in forum: XML
    Replies:
    1
    Views:
    586
    Florian Deissenboeck
    Nov 27, 2003
  4. Olaf Meyer
    Replies:
    2
    Views:
    673
    Olaf Meyer
    Jan 15, 2004
  5. Grand Apeiron
    Replies:
    7
    Views:
    1,729
    Peter Flynn
    Jan 20, 2004
Loading...

Share This Page