[xml] Line numbers for error messages



Hello,

I have a couple of SAX parsers implemented using libxml2. I wanted line
numbers in error messages so I wound up writing code that I think used
the internal interfaces of the library (xmlCreateFileParserCtxt and
xmlParseDocument). Inside my error callback I use getLineNumber when
building error messages. Is there a better way to get the line numbers
inside my error callback? 

It might make my question clearer if I include some code (then again it
might not...)

Here's how I set up the SAX context and start the parse:

    xmlParserCtxtPtr context=xmlCreateFileParserCtxt(document.c_str());
    // stuff omitted ...

    // ctxt is a field in the object, so when a callback gets 'this'
    // it can get access to the xmlParserCtxtPtr. 

    ctxt = context;             // need ctxt for error messages

    context->sax = &ddx_sax_parser;
    context->userData = this;
    context->validate = true;

    xmlParseDocument(context);

Later on in my error callback, I have:

    int line = getLineNumber(parser->ctxt);


Second question: It there a way to parse directly from an open FILE
pointer?

Thanks very much!
James

-- 
__________________________________________________________________________
James Gallagher                  The Distributed Oceanographic Data System
jgallagher gso uri edu               http://unidata.ucar.edu/packages/dods
Voice: 775.337.8612                                      Fax: 775.337.2105



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