Hello,

I am new to Xerces-C.  I want to validate the XML file with the
schema referenced within the instance doucment if there is one, otherwise
use a schema from an external location.  For using a schema from the
external location, I use the following code and it works fine.

 static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
 DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(gLS);
 parser =
((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS,
0);

 parser->setFeature(XMLUni::fgDOMNamespaces, true);
 parser->setFeature(XMLUni::fgXercesSchema, true);
 parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
 parser->setFeature(XMLUni::fgDOMValidation, true);
 parser->setFeature(XMLUni::fgDOMValidateIfSchema, true);
 parser->setFeature(XMLUni::fgXercesCacheGrammarFromParse, true);
 parser->setFeature(XMLUni::fgDOMDatatypeNormalization, true);

 parser->setFeature(XMLUni::fgDOMWhitespaceInElementContent, false);
 parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal, false);

 parser->setErrorHandler(&errorHandler);
 errorHandler.resetErrors();

 const char* msgInBuf = (const char*) strMessage;
 MemBufInputSource* memBufIS = new MemBufInputSource(reinterpret_cast<const
XMLByte*>(msgInBuf),
                                                     static_cast<unsigned
int>(strlen(msgInBuf) * sizeof(XMLByte)),
           memBufId,
           true);
 memBufIS->setEncoding(0);
 try {
   parser->resetDocumentPool();
   if (schemaLocation.contains(" ")) {
     parser->setProperty (XMLUni::fgXercesSchemaExternalSchemaLocation,
const_cast<XMLCh*>(XMLStringWrapper(schemaLocation).UnicodeForm()));
   } else {
     parser->setProperty
(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
const_cast<XMLCh*>(XMLStringWrapper(schemaLocation).UnicodeForm()));
   }

   Wrapper4InputSource wrapper(memBufIS);
   doc = parser->parse(wrapper);

Can anybody tell me how I can check whether a schema is referenced in the
instance document?

Thanks in advance

Mini.

Reply via email to