[xml] Receiving RELAX NG validity error callbacks



Can anyone help me with registering RELAX NG validity error callback functions?

I'm using the C RELAX NG API with xmlTextReader. I'm trying to register error callback functions for validity errors encoundtered in my *instance* document. I seem to be able to register handlers for all types of errors when parsing my RNG schema, and also well- formedness errors in my instance document. I can't seem to register error callbacks for *validity* errors in my instance doc as mandated by my RNG schema.

What's weird is that I do see these errors being reported to the console! These are the errors I want to receive in my C callbacks, but I can't find any way to register for them. Can anyone help? I've tried scouring xmllint.c for examples, but I just don't see where this happens. Other than that, I can't find any examples online.

Here's what I'm doing:



        char *docfurl = ".../golf.xml";
        char *schemafurl = ".../golf.rng";
        
        // RELAX NG Parser Context
        xmlRelaxNGParserCtxtPtr ctxt = xmlRelaxNGNewParserCtxt(schemafurl);
        xmlRelaxNGSetParserErrors(ctxt,
                                                          (xmlRelaxNGValidityErrorFunc)rngErr,
                                                          (xmlRelaxNGValidityWarningFunc)rngWarn,
                                                          NULL);
        
        // Parse schema
        xmlRelaxNGPtr schema = xmlRelaxNGParse(ctxt);
        
        // create reader
        xmlTextReaderPtr reader = xmlNewTextReaderFilename(docfurl);
        
        // associtate schema with reader
        xmlTextReaderRelaxNGSetSchema(reader, schema);
                
        // register some callbacks (apparently not the right ones)
        // never seems to be called
xmlTextReaderSetErrorHandler(reader, (xmlTextReaderErrorFunc) readerErr, NULL);
        // handles well-formedness errors in instance document
xmlTextReaderSetStructuredErrorHandler(reader, (xmlStructuredErrorFunc)structErr, NULL);
        
        while (xmlTextReaderRead(reader))
                ;

        NSLog(@"done. isValid: %i", xmlTextReaderIsValid(reader));



The callbacks you see registered here are usually called for different things, but none for validity errors in the instance doc caused by non-adherence to my RNG.

The reader *does* correctly report whether it was valid or not at the end, which is good... but I want to receive the individual validity errors too.

Can anyone help?



Todd Ditchendorf

Scandalous Software - Cocoa Developer Tools
http://scan.dalo.us






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]