Hi Steve,
Please find attached the cpp file with the loading schema code. You'll need
to link the cpp file with xercesc++ library (I've used the latest version
3.2.0).
Also, you'll need to provide the schema files list as arguments for the
executable.
Thanks,
Iulian.
On 27 February 2018 at 14:40, Steve Lawrence <[email protected]> wrote:
> Iulian,
>
> These errors are surprising to me. They look like the Xerces is unable
> to find certain simple types in the "sub" prefix namespace, but all
> those types are defined in XMLSchema_for_DFDL.xsd, so it's unclear to me
> why it can't find them.
>
> Would it be possible to provide your C++ code that loads these schemas
> and I can see if I can reproduce the issue?
>
> - Steve
>
> On 02/23/2018 04:28 AM, Iulian Mindrila wrote:
> > Hi,
> >
> > I’m trying to load the Daffodil dtd and xsd files in a grammar pool of
> > XercesC++. The purpose is to try to validate a DFDL schema file against
> it. I
> > load the grammas in the order indicated by Steve:
> >
> > "datatypes.dtd"
> >
> > "XMLSchema.dtd"
> >
> > "dafint.xsd"
> >
> > "DFDL_part1_simpletypes.xsd"
> >
> > "DFDL_part2_attributes.xsd"
> >
> > "DFDL_part3_model.xsd"
> >
> > "XMLSchema_for_DFDL.xsd"
> >
> > Everything works fine until the last xsd, XMLSchema_for_DFDL.xsd.
> >
> > As you can see below the errors starts with the line 153, referring to
> “sub”
> > namespace /<xsd:restriction base="sub:derivationControl">./
> >
> > Can you please advise if those errors can be fixed ?
> >
> > Thanks,
> >
> > Iulian.
> >
> > loading XMLSchema_for_DFDL.xsd
> >
> > XMLSchema_for_DFDL.xsd:153:51 error: type
> > 'http://www.w3.org/2001/XMLSchema:derivationControl' not found
> >
> > XMLSchema_for_DFDL.xsd:175:61 error: type
> > 'http://www.w3.org/2001/XMLSchema:reducedDerivationControl' not found
> >
> > XMLSchema_for_DFDL.xsd:174:23 error: unknown simpleType '{null}'
> >
> > XMLSchema_for_DFDL.xsd:186:51 error: type
> > 'http://www.w3.org/2001/XMLSchema:derivationControl' not found
> >
> > XMLSchema_for_DFDL.xsd:210:58 error: type
> > 'http://www.w3.org/2001/XMLSchema:typeDerivationControl' not found
> >
> > XMLSchema_for_DFDL.xsd:209:23 error: unknown simpleType '{null}'
> >
> > XMLSchema_for_DFDL.xsd:244:52 error: simpleType
> > 'http://www.w3.org/2001/XMLSchema:formChoice' for attribute
> > 'attributeFormDefault' not found
> >
> > XMLSchema_for_DFDL.xsd:246:52 error: simpleType
> > 'http://www.w3.org/2001/XMLSchema:formChoice' for attribute
> 'elementFormDefault'
> > not found
> >
> > XMLSchema_for_DFDL.xsd:316:21 error: simpleType
> > 'http://www.w3.org/2001/XMLSchema:allNNI' for attribute 'maxOccurs' not
> found
> >
> > XMLSchema_for_DFDL.xsd:471:30 error: simpleType
> > 'http://www.w3.org/2001/XMLSchema:derivationSet' for attribute 'final'
> not found
> >
> > XMLSchema_for_DFDL.xsd:473:30 error: simpleType
> > 'http://www.w3.org/2001/XMLSchema:derivationSet' for attribute 'block'
> not found
> >
> > XMLSchema_for_DFDL.xsd:721:59 error: type
> > 'http://www.w3.org/2001/XMLSchema:derivationControl' not found
> >
> > XMLSchema_for_DFDL.xsd:720:27 error: unknown simpleType '{null}'
> >
> > XMLSchema_for_DFDL.xsd:718:23 error: unknown simpleType '{null}'
> >
> > XMLSchema_for_DFDL.xsd:1477:70 error: simpleType
> > 'http://www.w3.org/2001/XMLSchema:simpleDerivationSet' for attribute
> 'final' not
> > found
> >
> > XMLSchema_for_DFDL.xsd:786:43 error: attribute 'form' has invalid target
> > namespace with respect to the base wildcard constraint or base has no
> wildcard
> >
> > XMLSchema_for_DFDL.xsd:809:43 error: attribute 'substitutionGroup' has
> invalid
> > target namespace with respect to the base wildcard constraint or base
> has no
> > wildcard
> >
> > XMLSchema_for_DFDL.xsd:809:43 error: attribute 'final' has invalid target
> > namespace with respect to the base wildcard constraint or base has no
> wildcard
> >
> > XMLSchema_for_DFDL.xsd:809:43 error: attribute 'abstract' has invalid
> target
> > namespace with respect to the base wildcard constraint or base has no
> wildcard
> >
> > XMLSchema_for_DFDL.xsd:869:43 error: attribute 'ref' is already defined
> in base
> >
> > XMLSchema_for_DFDL.xsd:921:49 error: attribute 'minOccurs' has invalid
> target
> > namespace with respect to the base wildcard constraint or base has no
> wildcard
> >
> > XMLSchema_for_DFDL.xsd:921:49 error: attribute 'maxOccurs' has invalid
> target
> > namespace with respect to the base wildcard constraint or base has no
> wildcard
> >
> > XMLSchema_for_DFDL.xsd:977:48 error: type
> > 'http://www.w3.org/2001/XMLSchema:allNNI' not found
> >
> > XMLSchema_for_DFDL.xsd:955:48 error: type of attribute 'maxOccurs' must
> be
> > derived by restriction from type of the corresponding attribute in the
> base
> >
> > XMLSchema_for_DFDL.xsd:1462:59 error: type
> > 'http://www.w3.org/2001/XMLSchema:derivationControl' not found
> >
> > XMLSchema_for_DFDL.xsd:1461:27 error: unknown simpleType '{null}'
> >
> > XMLSchema_for_DFDL.xsd:1459:23 error: unknown simpleType '{null}'
> >
>
>
#include <string>
#include <memory> // std::auto_ptr
#include <cstddef> // std::size_t
#include <iostream>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/validators/common/Grammar.hpp>
#include <xercesc/framework/XMLGrammarPoolImpl.hpp>
using namespace std;
using namespace xercesc;
class error_handler: public DOMErrorHandler
{
public:
error_handler () : failed_ (false) {}
bool
failed () const { return failed_; }
virtual bool
handleError (const xercesc::DOMError&);
private:
bool failed_;
};
DOMLSParser*
create_parser (XMLGrammarPool* pool)
{
const XMLCh ls_id [] = {chLatin_L, chLatin_S, chNull};
DOMImplementation* impl (
DOMImplementationRegistry::getDOMImplementation (ls_id));
DOMLSParser* parser (
impl->createLSParser (
DOMImplementationLS::MODE_SYNCHRONOUS,
0,
XMLPlatformUtils::fgMemoryManager,
pool));
DOMConfiguration* conf (parser->getDomConfig ());
// Commonly useful configuration.
//
conf->setParameter (XMLUni::fgDOMComments, false);
conf->setParameter (XMLUni::fgDOMDatatypeNormalization, true);
conf->setParameter (XMLUni::fgDOMEntities, false);
conf->setParameter (XMLUni::fgDOMNamespaces, true);
conf->setParameter (XMLUni::fgDOMElementContentWhitespace, false);
// Enable validation.
//
conf->setParameter (XMLUni::fgDOMValidate, true);
conf->setParameter (XMLUni::fgXercesSchema, true);
conf->setParameter (XMLUni::fgXercesSchemaFullChecking, false);
// Use the loaded grammar during parsing.
//
conf->setParameter (XMLUni::fgXercesUseCachedGrammarInParse, true);
// Don't load schemas from any other source (e.g., from XML document's
// xsi:schemaLocation attributes).
//
conf->setParameter (XMLUni::fgXercesLoadSchema, false);
// Xerces-C++ 3.1.0 is the first version with working multi
// import support.
//
#if _XERCES_VERSION >= 30100
conf->setParameter (XMLUni::fgXercesHandleMultipleImports, true);
#endif
// We will release the DOM document ourselves.
//
conf->setParameter (XMLUni::fgXercesUserAdoptsDOMDocument, true);
return parser;
}
int
main (int argc, char* argv[])
{
if (argc < 2)
{
cerr << "usage: " << argv[0] << " [test.xsd ... ] [test.xml ...]" << endl;
return 1;
}
XMLPlatformUtils::Initialize ();
int r (0);
while (true)
{
MemoryManager* mm (XMLPlatformUtils::fgMemoryManager);
auto_ptr<XMLGrammarPool> gp (new XMLGrammarPoolImpl (mm));
int i (1);
// Load the schemas into grammar pool.
//
{
DOMLSParser* parser (create_parser (gp.get ()));
error_handler eh;
parser->getDomConfig ()->setParameter (XMLUni::fgDOMErrorHandler, &eh);
for (; i < argc; ++i)
{
string s (argv[i]);
size_t n (s.size ());
if (n < 5 || s[n - 4] != '.' || s[n - 3] != 'x' ||
s[n - 2] != 's' || s[n - 1] != 'd')
break;
cerr << "loading " << s << endl;
if (!parser->loadGrammar (s.c_str (), Grammar::SchemaGrammarType, true))
{
cerr << s << ": error: unable to load" << endl;
r = 1;
break;
}
if (eh.failed ())
{
r = 1;
break;
}
}
parser->release ();
if (r != 0)
break;
}
// Lock the grammar pool. This is necessary if we plan to use the
// same grammar pool in multiple threads (this way we can reuse the
// same grammar in multiple parsers). Locking the pool disallows any
// modifications to the pool, such as an attempt by one of the threads
// to cache additional schemas.
//
gp->lockPool ();
// Parse the XML documents.
//
DOMLSParser* parser (create_parser (gp.get ()));
error_handler eh;
parser->getDomConfig ()->setParameter (XMLUni::fgDOMErrorHandler, &eh);
for (; i < argc; ++i)
{
cerr << "parsing " << argv[i] << endl;
DOMDocument* doc (parser->parseURI (argv[i]));
if (doc)
doc->release ();
if (eh.failed ())
{
r = 1;
break;
}
}
parser->release ();
break;
}
XMLPlatformUtils::Terminate ();
return r;
}
bool error_handler::
handleError (const xercesc::DOMError& e)
{
bool warn (e.getSeverity() == DOMError::DOM_SEVERITY_WARNING);
if (!warn)
failed_ = true;
DOMLocator* loc (e.getLocation ());
char* uri (XMLString::transcode (loc->getURI ()));
char* msg (XMLString::transcode (e.getMessage ()));
cerr << uri << ":"
<< loc->getLineNumber () << ":" << loc->getColumnNumber () << " "
<< (warn ? "warning: " : "error: ") << msg << endl;
XMLString::release (&uri);
XMLString::release (&msg);
return true;
}