Re: [xml] ValidityError & ValidityWarning

Date view Thread view Subject view Author view

From: Daniel Veillard (Daniel.Veillard@w3.org)
Date: Sat Mar 18 2000 - 06:10:20 EST


On Fri, Mar 17, 2000 at 10:58:24AM -0800, Kenny Hom wrote:
>
> Is there a way to override xmlParserValidityError and
> xmlParserValidityWarning as the default functions without using SAX?
> When validating XML against a DTD, I want to capture the errors and
> warning messages in my own log rather than have them sent to standard
> output.
>
> I know there was a similar question asked awhile back regarding
> xmlParserError and xmlParserWarning, but I think there may be a
> different answer to my question.

  Well it's a rather similar answer excexpt that the validity callbacks
are not part of the SAX callback but associated to teh parser context
itself.

Similar code is available in tester.c, here is what you're looking for:

---------------------------
xmlParserCtxtPtr ctxt;
xmlSAXHandler silent, *old;

/* create a parsing context */
ctxt = xmlCreateFileParserCtxt(filename);

/* override the validation callbacks */
ctxt->vctxt.warning = myValidityWarning;
ctxt->vctxt.error = myValidityError;

xmlParseDocument(ctxt);

ret = ctxt->wellFormed;
doc = ctxt->myDoc;
xmlFreeParserCtxt(ctxt);

/* if the document wasn't well-formed, drop the whole output */
if (!ret) {
    xmlFreeDoc(doc);
    doc = NULL;
}
---------------------------

Daniel

-- 
Daniel.Veillard@w3.org | W3C, INRIA Rhone-Alpes  | Today's Bookmarks :
Tel : +33 476 615 257  | 655, avenue de l'Europe | Linux XML libxml WWW
Fax : +33 476 615 207  | 38330 Montbonnot FRANCE | Gnome rpm2html rpmfind
 http://www.w3.org/People/all#veillard%40w3.org  | RPM badminton Kaffe
----
Message from the list xml@xmlsoft.org
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@xmlsoft.org


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Aug 02 2000 - 12:30:08 EDT