[Expat-discuss] Verify xml-file with dtd?

Reid Spencer reid at x10sys.com
Fri Mar 4 19:30:40 CET 2005


Expat doesn't support document validation. It only does a
well-formedness check on the input (making sure tags are properly
constructed and balanced). 

If you need validation, you can either roll your own, use XML Schema or
Relax NG, or use an xml parser that supports validation (libxml2,
Xerces).

Reid.

On Fri, 2005-03-04 at 08:33, Mikael Ryding (LI/EAB) wrote:
> Hi!
> 
> I'm writing a program that uses EXPAT to parse an xml-file and to verify its structure with a dtd-file, but it ONLY verifies the syntax for the xml-ile and dtd-file separately, I don't manage to get the parser to compare the files and verify that the xml-file "implements" the dtd so to speak. I can use any valid DTD (that has nothing to do with my xml-file) and the parser finds it ok.
> 
> 
> Does someone have an idea what I do wrong? Below is part of the code that includes the DTD-parts (everything else removed):
> ---------------------------
> 
> int dtdHandler (XML_Parser parser, const XML_Char *context,  const XML_Char *base,  
>                       const XML_Char *systemId,  const XML_Char *publicId)
> {
>   XML_Parser dtdParser = XML_ExternalEntityParserCreate(parser, context, 0);
>   status = XML_Parse(dtdParser, buf, len, 1);
>   if (!status) {
>     printf("dtdparsing: %s at line %d, column: %d, errorCode: %d\n",
>            XML_ErrorString(XML_GetErrorCode(dtdParser)),
>            XML_GetCurrentLineNumber(dtdParser),
>            XML_GetCurrentColumnNumber(dtdParser));
>     return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
>   }
>   return status; 
> }
> ----------------------------
> int main ()
> {
>   /* Set user data */
>   XML_SetUserData(parser, fd_p);
> 
>   /* DTD parsing */
>   XML_SetExternalEntityRefHandler(parser, dtdHandler);
>   XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
> 
>   /* Set element and character data handler */
>   XML_SetElementHandler(parser, startElement, endElement);
> 
>   do {  
>     if (!XML_Parse(parser, buf, len, len==0)) {
>       printf("xmlparsing: %s at line %d, column: %d\n",
>               XML_ErrorString(XML_GetErrorCode(parser)),
>               XML_GetCurrentLineNumber(parser),
>               XML_GetCurrentColumnNumber(parser));
>  
>     } 
> }
> 
> 
> Regards, Mikael
> _______________________________________________
> Expat-discuss mailing list
> Expat-discuss at libexpat.org
> http://mail.libexpat.org/mailman/listinfo/expat-discuss
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mail.libexpat.org/pipermail/expat-discuss/attachments/20050304/7873b078/attachment.pgp


More information about the Expat-discuss mailing list