Re: [xml] DTD validation not restrictive enough?
- From: Morus Walter <morus walter tanto-xipolis de>
- To: xml gnome org
- Subject: Re: [xml] DTD validation not restrictive enough?
- Date: Mon, 17 Nov 2003 11:20:09 +0100
I hope it's ok, if I put this on the list again - you replied to me
directly.
Jarek Dukat writes:
Morus Walter wrote:
it's most probably due to an inapropriate usage of the library.
My code is very simple:
xmlDoc *doc = xmlParseFile("foo.xml");
if (doc == NULL) {
// ...
} else {
mlDtdPtr dtd = xmlParseDTD(0, (unsigned char*)"cfg.dtd");
xmlValidCtxt cvp;
cvp.userData = (void *) stderr;
cvp.error = (xmlValidityErrorFunc) fprintf;
cvp.warning = (xmlValidityWarningFunc) fprintf;
if ( !xmlValidateDtd(&cvp, doc, dtd) ) {
// ...
}
// ...
}
I'm not familiar enough with the C API to guess what might be wrong in your
code, but you might have a look at xmllints sources, to see how validation
is done.
xmllint sources are very complex, buf if noone suggests simple solution
I'll have to take a closer look at it. Thanks.
the related section does not look very different to what you do,
except the initialisation of the xmlValidCtxt:
/*
* A posteriori validation test
*/
if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) {
xmlDtdPtr dtd;
if ((timing) && (!repeat)) {
startTimer();
}
if (dtdvalid != NULL)
dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid);
else
dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL);
if ((timing) && (!repeat)) {
endTimer("Parsing DTD");
}
if (dtd == NULL) {
if (dtdvalid != NULL)
xmlGenericError(xmlGenericErrorContext,
"Could not parse DTD %s\n", dtdvalid);
else
xmlGenericError(xmlGenericErrorContext,
"Could not parse DTD %s\n", dtdvalidfpi);
progresult = 2;
} else {
xmlValidCtxtPtr cvp;
if ((cvp = xmlNewValidCtxt()) == NULL) {
xmlGenericError(xmlGenericErrorContext,
"Couldn't allocate validation context\n");
exit(-1);
}
cvp->userData = (void *) stderr;
cvp->error = (xmlValidityErrorFunc) fprintf;
cvp->warning = (xmlValidityWarningFunc) fprintf;
if ((timing) && (!repeat)) {
startTimer();
}
if (!xmlValidateDtd(cvp, doc, dtd)) {
if (dtdvalid != NULL)
xmlGenericError(xmlGenericErrorContext,
"Document %s does not validate against %s\n",
filename, dtdvalid);
else
xmlGenericError(xmlGenericErrorContext,
"Document %s does not validate against %s\n",
filename, dtdvalidfpi);
progresult = 3;
}
if ((timing) && (!repeat)) {
endTimer("Validating against DTD");
}
xmlFreeValidCtxt(cvp);
xmlFreeDtd(dtd);
}
}
xmlNewValidCtxt just initializes the structure with 0's, something you're
missing, when you allocate the structure on the stack (at least if I remember
C programming correctly).
Morus
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]