Hello,
I have an XML file validated by xerces against a schema_1.xsd file which
xs:include's another schema_2.xsd file.
So far so good, by now I would like to move those files into memory.
I have been using a MemBufInputSource before for this, but there wasn't
any xs:include then.
Of course I cannot alter the schemas in any way. :)
Here is what I have been trying (xerces 3.x version) :
using namespace XERCES_CPP_NAMESPACE;
DOMLSParser& parser = ...
parser.getDomConfig()->setParameter(
XMLUni::fgXercesUserAdoptsDOMDocument, true );
parser.getDomConfig()->setParameter( XMLUni::fgDOMNamespaces, true );
parser.getDomConfig()->setParameter( XMLUni::fgDOMDatatypeNormalization,
true );
parser.getDomConfig()->setParameter( XMLUni::fgXercesSchema, true );
parser.getDomConfig()->setParameter( XMLUni::fgDOMValidate, true );
parser.getDomConfig()->setParameter(
XMLUni::fgXercesUseCachedGrammarInParse, true );
const std::string schema_1 = "<xs:schema
xmlns:xs='http://www.w3.org/2001/XMLSchema'>"
" <xs:include schemaLocation='schema_2.xsd'/>"
" <xs:element name='element'>"
" <xs:complexType>"
" <xs:attribute name='attribute'
type='type'/>"
" </xs:complexType>"
" </xs:element>"
"</xs:schema>";
const std::string schema_2 = "<xs:schema
xmlns:xs='http://www.w3.org/2001/XMLSchema'>"
" <xs:simpleType name='type'>"
" <xs:restriction base='xs:int'/>"
" </xs:simpleType>"
"</xs:schema>";
{
MemBufInputSource source( reinterpret_cast< const XMLByte* >(
schema_1.c_str() ), schema_1.size(), "schema_1.xsd" );
Wrapper4InputSource input( &source, false );
if( ! parser.loadGrammar( &input, Grammar::SchemaGrammarType, true ) )
throw ...
}
{
MemBufInputSource source( reinterpret_cast< const XMLByte* >(
schema_2.c_str() ), schema_2.size(), "schema_2.xsd" );
Wrapper4InputSource input( &source, false );
if( ! parser.loadGrammar( &input, Grammar::SchemaGrammarType, true ) )
throw ...
}
And then parsing the following XML document : <element attribute='42'/>
Yields the validation error : unable to find validator for simple type
of attribute 'attribute'
The validation succeeds however if the content of schema_2 is moved to a
schema_2.xsd file in the working directory.
Is what I am looking for theoretically possible ?
If yes I would really appreciate being pointed to the right direction. :)
Thanks a lot for any hint !
Regards,
MAT.