Re: [xml] xmlParseFile return value

On Thu, Jan 17, 2002 at 02:57:33PM -0500, Wei Qin wrote:

I set xmlDoValidityCheckingDefaultValue to 1.
Some elements in a xml file miss required attributes. The parser prints
out some error messages, but still return a non-null document ptr.
How can I tell this ptr from a fully valid document ptr?

   You can either:
     - trap the message and set a flag about the error somewhere.
     - use a lower level parsing API with more access like:
       xmlParserCtxtPtr ctxt;
       int wellformed, valid;
       xmlDocPtr doc;

       xmlDoValidityCheckingDefaultValue = 1
       ctxt = xmlCreateFileParserCtxt(filename);
       wellformed, = ctxt->wellFormed;
       valid = ctxt->valid;
       doc = ctxt->myDoc;
       if (!wellformed,) {
           doc = NULL;
       at that point you have valid, wellformed, and if well-formed
       the resulting document.


Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml Gnome XML XSLT toolkit | Rpmfind RPM search engine

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