Re: [xml] Validating xml with xmlValidateDtd



On Tue, Nov 27, 2001 at 01:47:16PM +0100, Gert Marginet wrote:
Hi,

I'm trying to use this function to do the next :


I have already an XML file in memory via a char pointer. And I have a DTD in a file on my disk.  There is 
no ref to the DTD in the XML, but I want to validate it whit my DTD.

I already found a lot of code samples in the mail archive, but some times I get a core dump, I only get a 
core dump when the xml is not valid.

Can annybody give me a code sample to on how to use this function?

  Use the existing code from xmllint.c which does exactly this when passed
the --memory and --dtdvalid flags !

Direct cut and paste from the code:
-----------------
        doc = xmlParseMemory((char *) base, info.st_size);
-----------------

-----------------
        xmlDtdPtr dtd;

        dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid);
        if (dtd == NULL) {
            xmlGenericError(xmlGenericErrorContext,
                    "Could not parse DTD %s\n", dtdvalid);
            progresult = 2;
        } else {
            xmlValidCtxt cvp;
            if ((timing) && (!repeat)) {
                gettimeofday(&begin, NULL);
            }
            cvp.userData = (void *) stderr;                                                 cvp.error    = 
(xmlValidityErrorFunc) fprintf;                                  cvp.warning  = (xmlValidityWarningFunc) 
fprintf;
            if (!xmlValidateDtd(&cvp, doc, dtd)) {
                xmlGenericError(xmlGenericErrorContext,
                        "Document %s does not validate against %s\n",
                        filename, dtdvalid);
                progresult = 3;
            }
       }
-----------------

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]