[xml] libxml vs relaxNG question : File name and line number.



Hi all,

Following a suggestion from Daniel, I`m posting my question to the xmllist.  
Our application want to print parsing errors detected through RelaxNG into syslog.
But the line number and file name are not given to the error callback.  Any idea how to make that information 
showed ? Here`s the code that we are using : 

void cfg_parsingErrCB ( void       * ptr,
                        const char * msg, 
                        ...)
{
...
}

    // create a parser context
    ctxt = xmlNewParserCtxt();
    if (ctxt == NULL) {
        UTL_ABORT1( CFG_ModuleId,
                    "*** Failed to a parser context" );
        return;
    }


    
    
       
    // Create a context pointer on the validation file
    relaxngContextPtr = xmlRelaxNGNewParserCtxt(validationFile);
    if ( relaxngContextPtr == NULL )
    {
        UTL_ABORT( CFG_ModuleId,
                   "*** Failed to create a parser context upon validation file %s", validationFile  );
        return;
    } 

    xmlRelaxNGSetParserErrors ( relaxngContextPtr,
                                (xmlRelaxNGValidityErrorFunc)   cfg_parsingErrCB,
                                (xmlRelaxNGValidityWarningFunc) cfg_parsingErrCB,
                                stderr);

 
    // Set all Error callbacks for dealing with CLF logs 
    xmlSetGenericErrorFunc    ( ctxt, (xmlGenericErrorFunc) cfg_parsingErrCB );
    



    // Validation of the validation file :) 
    schema  =  xmlRelaxNGParse( relaxngContextPtr );
    if ( schema == NULL ){
        UTL_ABORT( CFG_ModuleId,
                   "*** Failed to validate the validation file %s", validationFile  );
        return;

    } 
    xmlRelaxNGFreeParserCtxt(relaxngContextPtr);

    validSchema = xmlRelaxNGNewValidCtxt  (schema);
    if ( validSchema == NULL ){
        UTL_ABORT( CFG_ModuleId,
                   "*** Failed to validate the validation file %s", validationFile  );
        return;
    } 


   xmlRelaxNGSetValidErrors ( validSchema,
                              (xmlRelaxNGValidityErrorFunc)   cfg_parsingErrCB,
                              (xmlRelaxNGValidityWarningFunc) cfg_parsingErrCB,
                               stderr);


    /* Read the configuration file */
    doc = xmlCtxtReadFile(ctxt, configurationFile, NULL, 0);

    if (doc == NULL) {
        if (configurationFile == NULL) {
            UTL_ABORT( CFG_ModuleId,
                       "*** Failed to parse configuration file %s. File does not exist.",
                       DEFAULT_CONFIG_FILE_NAME );
            return;
        }
        else {
            UTL_ABORT( CFG_ModuleId,
                       "*** Failed to parse configuration file %s. Invalid file contents.",
                       configurationFile );
            return;                       
        }
    } 
    
    /* Compare configuration file with the schema */
    if ( xmlRelaxNGValidateDoc ( validSchema, doc ) != 0 )
    {
            UTL_ABORT( CFG_ModuleId,
                       "*** Failed to parse configuration file %s. File didn't respect validation file %s.",
                       configurationFile, validationFile );
            return;                       

    }else {
        UTL_LOG1( UTL_LOG_DEBUG,
                 CFG_ModuleId,
                 "*** Configuration file parsed successfully ! " );
    }




-----Original Message-----
From: Daniel Veillard [mailto:daniel veillard com] 
Sent: Saturday, December 24, 2005 6:27 AM
To: Jean-Francois Dupont-Viel (QC/EMC)
Cc: daniel veillard com
Subject: Re: libxml vs realxng question

On Fri, Dec 23, 2005 at 02:37:34PM -0500, Jean-Francois Dupont-Viel (QC/EMC) wrote:
Salut Daniel,
 
I have a question concerning error handling when using relaxng in libxml.
I am using a callback for error detection as our software use a special API to log messages.
When a schema error is detected, the line number and file number isn`t 
showned in the callback while a normal XML error, the file and number is showed.
 
How can I have the line number and file name with relaxng schema error ?

  Hum, possible, mais ca depends peut etre 
    1/ de la version de libxml2
    2/ du type de callback d'erreur demandees (structuree ou pas)

Le mieux c'est de demander sur la liste avec un peu plus de details

Merci et passes de belles fêtes ! 

 merci, de meme !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | 



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