Re: IXMLDOMSchemaCollection::add()

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




> The method returns an error code, which #import-generated smart wrapper
> converts into _com_error exception. Catch the exception, see what the
> error code and error message is.

Error: "Validate failed because the root element had no associated
DTD/schema."

I don't understand this. This error occur in my implementation (Handler
class) of ISAXErrorHandler::error(), but this object is not assigned yet!:

//Create handler class
Handler * pEH = new Handler();

// Load schema from memory (resources) into DOMDocument
IXMLDOMDocument2Ptr domSchema = NULL;
HRESULT hr = domSchema.CreateInstance("Msxml2.DOMDocument.4.0");
BSTR xml = CString((char*)hRes, dwFileLength).AllocSysString();
domSchema->loadXML(xml);
SysFreeString(xml);

ISAXXMLReaderPtr pSAXReader = NULL;
hr = pSAXReader.CreateInstance(__uuidof(MSXML2::SAXXMLReader40));

IXMLDOMSchemaCollection2Ptr pSchema = NULL;
hr = pSchema.CreateInstance(__uuidof(MSXML2::XMLSchemaCache40));

try {
//An exception occur here and next line of code is Handler::error()
pSchema->add(L"", &CComVariant(domSchema));
} catch (_com_error e) {
AfxMessageBox(e.Description());
AfxMessageBox(e.ErrorMessage());
} catch (...) {
AfxMessageBox("Unknown error.");
}

pSAXReader->putFeature(MUS("schema-validation"), VARIANT_TRUE);
pSAXReader->putProperty(MUS("schemas"),
CComVariant(pSchema.GetInterfacePtr()));

//Handler was assigned here! Not before this line.
hr = pSAXReader->putErrorHandler(pEH);


.



Relevant Pages

  • Re: Structured exception information
    ... Doesn't feel as type-safe as advertised. ... What, _exactly_, will the handler do with the separate bits? ... Looking up the localized error message in the dictionary based on the *type-safe* error code that it got from the exception object, ... I'm looking forward to see a convincing solution for error code and the dictionary. ...
    (comp.lang.ada)
  • Re: event firing and first-chance 0x800706bf (800706bf)
    ... > if the client my server is firing events is killed then i see an ... > exception that is handled. ... you will get an error code (not sure which - might be ... event handler. ...
    (microsoft.public.vc.atl)
  • Re: Try Finally...
    ... Now we can protect every more or less specialized action ... an error indication (exception or error code) has to be ... an according exception handler can be inserted into the code. ... resources, as they are related to specific actions. ...
    (comp.lang.pascal.delphi.misc)
  • Re: WinForms bug? ThreadException not invoked on Exceptions in system code pre-processing the me
    ... Message Queue and invoking the appropriate handler. ... if an Exception is raised during the PRE-PROCESSING of a Windows ... And because any handling will probably fail if there is no memory, the CLR will terminate the application without attempting to call the ApplicationException or UnhandledException events. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: BackgroungWork taske ended for no appearent reason
    ... To do the same thing with Try/Catch blocks requires wrapping every file access with a Do While ... ... If there was any exception thrown in your DoWork event handler, ... If the operation raises an exception that your code does not handle, ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vb)