Re: [xml] DTD Validation Problem



>  It's again a URI versus Windows File Path problem. Someone
> using Windows should look at it, I won't I don't have any Windows
> box.

I have one :)

> file:///c:/temp/dtd/xml1.dtd should work, if it doesn't it is a bug.

That works, but things like this

  C:\temp> xmllint --dtdvalid dtd\xml1.dtd xml\xml1.xml

don't work and that only for the DTD. The XML document you can specify as you please, it always works.

The reason is, xmlSAXParseDTD calls the entity resolver to fetch the DTD and that one calls xmlBuildURI, which fails with a Windows path. Making the system ID canonic before it reaches the entity resolver solves the issue.

The patch is attached. If there are no objections, I'll apply it.

Ciao,
Igor

Index: parser.c
===================================================================
RCS file: /cvs/gnome/libxml2/parser.c,v
retrieving revision 1.378
diff -c -r1.378 parser.c
*** parser.c    19 Aug 2004 02:17:27 -0000      1.378
--- parser.c    24 Aug 2004 16:01:10 -0000
***************
*** 10150,10155 ****
--- 10150,10156 ----
      xmlParserCtxtPtr ctxt;
      xmlParserInputPtr input = NULL;
      xmlCharEncoding enc;
+     xmlChar* systemIdCanonic;
  
      if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL);
  
***************
*** 10167,10182 ****
          ctxt->sax = sax;
          ctxt->userData = ctxt;
      }
  
      /*
       * Ask the Entity resolver to load the damn thing
       */
  
      if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL))
!       input = ctxt->sax->resolveEntity(ctxt, ExternalID, SystemID);
      if (input == NULL) {
          if (sax != NULL) ctxt->sax = NULL;
        xmlFreeParserCtxt(ctxt);
        return(NULL);
      }
  
--- 10168,10193 ----
          ctxt->sax = sax;
          ctxt->userData = ctxt;
      }
+     
+     /*
+      * Canonicalise the system ID
+      */
+     systemIdCanonic = xmlCanonicPath(SystemID);
+     if (systemIdCanonic == NULL) {
+       xmlFreeParserCtxt(ctxt);
+       return(NULL);
+     }
  
      /*
       * Ask the Entity resolver to load the damn thing
       */
  
      if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL))
!       input = ctxt->sax->resolveEntity(ctxt, ExternalID, systemIdCanonic);
      if (input == NULL) {
          if (sax != NULL) ctxt->sax = NULL;
        xmlFreeParserCtxt(ctxt);
+       xmlFree(systemIdCanonic);
        return(NULL);
      }
  
***************
*** 10190,10196 ****
      }
  
      if (input->filename == NULL)
!       input->filename = (char *) xmlCanonicPath(SystemID);
      input->line = 1;
      input->col = 1;
      input->base = ctxt->input->cur;
--- 10201,10209 ----
      }
  
      if (input->filename == NULL)
!       input->filename = (char *) systemIdCanonic;
!     else
!       xmlFree(systemIdCanonic);
      input->line = 1;
      input->col = 1;
      input->base = ctxt->input->cur;


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