Re: [xml] Issue in DTD validation thru Libxml



Senthil -

My guess, without seeing your full code, is that you didn't initialize
cvp:

cvp = xmlNewValidCtxt();

The following works correctly on your test files, returning 0 rather
than 1:

int
main() {
        int valid;
        xmlDocPtr doc;
        xmlValidCtxtPtr cvp;
        xmlDtdPtr dtd;
        cvp = xmlNewValidCtxt();
        doc = xmlReadFile("test.xml", NULL, 0);
        dtd = xmlParseDTD(NULL,"sample.dtd" );

        valid=xmlValidateDtd(cvp, doc, dtd); 
        printf("%d\n", valid);
        return 0;
}

xmllint.c is a full of usable examples for carrying out basic functions
such as this.

Cheers,
John

On Thu, 2004-01-22 at 07:39, Senthil S wrote:
Hello everybody,
                      I am new to this forum.I need a great help from
this forum.
Actually i am using libxml 2.2.6  for creating dom(xmldocptr)  in unix
environment.I have a DTD file already existing in file format.I need
to validate the DTD with the dom.
 
The following is the code construct:
 
 doc = xmlReadFile("sample.xml", NULL, 0);
 dtd = xmlParseDTD(NULL,"sample.dtd" ); /* parse the DTD */
 valid=xmlValidateDtd(&cvp, doc, dtd); 
 
the input sample.xml is
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "sample.dtd">
<note>
 <from/>
</note>
 
sample.dtd
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
 
when i validate the xml file with the dtd using the above code, it
returns 1 which describes xml is valid.
 
To my understanding of xml, it should be invalid as the
to,from,heading are sequence children to note element. 
Could anybody help me to resolve this issue using libxml?
 
Thanks,
S.Senthil
 
 
 
 




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