RE: [xml] Re: Unwanted logging in htmlParseDoc()



The way to turn the logging off is to set up your own logging function.  We had a similar problem with Mac OSX and used the initGenericErrorDefaultFunc(). 
 
This way I was able to use our personal error handling logging functions that will only be used in debug versions.  Otherwise the function ouputs nothing and the error is ignored.
-----Original Message-----
From: xml-bounces gnome org [mailto:xml-bounces gnome org]On Behalf Of David Gatwood
Sent: Wednesday, May 26, 2004 12:31 PM
To: xml gnome org
Subject: [xml] Re: Unwanted logging in htmlParseDoc()

On May 25, 2004, at 8:05 AM, Paul Collins wrote:


My app uses htmlParseDoc() to get URLs from html documents. It works

great, but there is extensive logging of all parse errors to stderr

whenever the html isn't perfect (i.e., 99% of the time). Is there a way

to turn this off? The logging really clogs up our users' console logs.


I've looked at the online docs but haven't been able to figure out an

answer. Would htmlParseFile() make a difference? Should I be doing

something with a context?


I'm using libxml2.2 as shipped on Mac OS X 10.3.0. We've also use 2.6.2

which seems to do the same.


OS X users can check out the app, which displays images automatically

from web sites, and see what it does in the Console.


I ran into the same problem trying to use it in a tool related to HeaderDoc 8. Eventually, I gave up and redirected stderr to /dev/null during the parse. It works like a charm. I pasted a code fragment at the bottom....



Hope that helps,

David



void setup_redirection(void);

void redirect_stderr_to_null(void);

void restore_stderr(void);

main(...)

{

setup_redirection();

.

.

.

redirect_stderr_to_null();

        htmlParseWhateverFunction(...);

restore_stderr();

.

.

.

}


void setup_redirection(void)

{

int fail = 0, localDebug = 0;


nullfd = open("/dev/null", (O_RDWR|O_NONBLOCK), 0);

stderrfd = dup(STDERR_FILENO);


if (nullfd == -1) {

fprintf(ERRS, "WARNING: Could not open /dev/null!\n");

fail = 1;

}

if (stderrfd == -1) {

fprintf(ERRS, "WARNING: Could not dup stderr!\n");

fail = 1;

}

if (!fail && localDebug) {

printf("Dup successful\n");

}

}


void redirect_stderr_to_null(void)

{

if ((nullfd != -1) && (stderrfd != -1)) {

dup2(nullfd, STDERR_FILENO);

}

}


void restore_stderr(void)

{

if ((nullfd != -1) && (stderrfd != -1)) {

dup2(stderrfd, STDERR_FILENO);

}

}



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