Ideally what I think I want to do is get rid of needing the thing in the
first place. I don't use DTDs, I don't use any custom entities,. therefore
I should not need this whole EntityResolver mess. Anyway, I do have a
program that I wrote that validates an XML against a schema and prints out
what it is doing via the callbacks. This program doesn't require me
loading any EntityResolver object into the parser, so what is really
different about it vs. the other code? Here is the basic steps I do in it
to set up the SAX2 parser. It is only marginally different than what I do
in my production programs:
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cerr << "Error during initialization! :\n";
cerr << "Exception message is: \n" << message << "\n";
XMLString::release(&message);
return 1;
}
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgXercesDynamic, true);
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); // optional
parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal, true);
parser->setValidationConstraintFatal(true);
parser->setExitOnFirstFatalError(true);
MySAX2Handler* defaultHandler = new MySAX2Handler();
parser->setContentHandler(defaultHandler);
parser->setErrorHandler(defaultHandler);
I can post this whole program as an attachment if anyone is interested.
On Wed, May 22, 2013 at 4:06 PM, Kelly Beard <[email protected]>wrote:
> I don't understand entities and why I need to extend class EntityResolver.
> Based on the documentation, it seems like I don't need to go through this
> step. When I read about entities, I see the usual &apos, &, ", et
> al. I don't have any custom entities.
>
> I have an XML document, call it authNotify. I use an XSD (authNotify.xsd)
> & SAX2 to validate this document. If I don't call setEntityResolver() in
> my code, the parser bombs with a message like the following:
>
> Warning at file , line=0, column=0, An exception occurred!
> Type:RuntimeException, Message:Warning: The primary document entity could
> not be opened. Id=/tmp/authNotify.xsd
>
>
> So, based on my understanding of how to set up SAX2, my basic flow is to
> do something like so:
>
> XMLPlatformUtils::Initialize();
>
> parser = XMLReaderFactory::createXMLReader();
> parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
> parser->setFeature(XMLUni::fgXercesDynamic, true);
> parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
> parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal, false);
>
> defaultHandler = new AuthNotifyHandler();
> AuthNotifyResolver *authResolver = new AuthNotifyResolver();
> parser->setContentHandler(defaultHandler);
> parser->setErrorHandler(defaultHandler);
> parser->setEntityResolver(authResolver);
>
> Where AuthNotifyHandler is derived from DefaultHandler and
> AuthNotifyResolver is derived from EntityResolver.
>
> When resolveEntity() is called, the parameters publicID and systemID are
> both set to authNotify.xsd. In the traditional compareString(), if I
> change the comparison to return 0, all heck breaks loose.
>
> I don't know if I'm doing something wrong in the parser set-up, or if
> something is wrong elsewhere.
>
> So, lost here. Any help?
>
> --
> Kelly Beard
>
--
Kelly Beard