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);
       xmlParseDocument(ctxt);
       wellformed, = ctxt->wellFormed;
       valid = ctxt->valid;
       doc = ctxt->myDoc;
       xmlFreeParserCtxt(ctxt);
       if (!wellformed,) {
           xmlFreeDoc(doc);
           doc = NULL;
       }
       -----------------
       at that point you have valid, wellformed, and if well-formed
       the resulting document.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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