Hi all,

How can I configure Xerces C++ to perform nested XSD validation on an XML
input such as in the following (please note the usage of the 2 XSDs
shiporder.xsd and item.xsd, that's how I would like it to be because <item>
is inserted into <shiporder> by a separate c++ thread XYZ):

<?xml version="1.0" encoding="UTF-8"?>

<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:noNamespaceSchemaLocation="shiporder.xsd">
  <orderperson>John Smith</orderperson>
  <shipto>
    <name>Ola Nordmann</name>
    <address>Langgt 23</address>
    <city>4000 Stavanger</city>
    <country>Norway</country>
  </shipto>
  <item
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:noNamespaceSchemaLocation="item.xsd">
    <title>Hide your heart</title>
    <quantity>1</quantity>
    <price>9.90</price>
  </item>
</shiporder>

Currently my DOM parser is configured like so:
XERCES_CPP_NAMESPACE::XercesDOMParser dom_parser;
XERCES_CPP_NAMESPACE::MemBufInputSource in_memory_schema_buffer((XMLByte*)
schema_source.c_str(), schema_source.size(), "my schema buffer");
if (dom_parser.loadGrammar(in_memory_schema_buffer,
XERCES_CPP_NAMESPACE::Grammar::SchemaGrammarType, true) == NULL)
{
request_details->setError(SchemaError_DOMParserCouldNotLoadSchema, "Failed
to load schema");
return false;
}

XMLValidator_ParserErrorHandler error_handler;
dom_parser.setErrorHandler(&error_handler);
dom_parser.setValidationScheme(XERCES_CPP_NAMESPACE::XercesDOMParser::Val_Always);
dom_parser.setDoNamespaces(true);
dom_parser.setDoSchema(true);
dom_parser.setValidationConstraintFatal(true);
dom_parser.useCachedGrammarInParse(true);

Is this possible? is it a valid thing to do?
Any example/explanation is much appreciated.

Kind regards
Bodi N.

Reply via email to