Re: [xml] RFE: Schema-validation API



Hi Daniel,

Please find attached a patch to add a new API as discussed
below.  The API has been tested via my own project,
but if you would like an additional patch for testschemas.c
let me know.

Regards,
Steve Ball

You wrote:
On Tue, Oct 14, 2003 at 10:13:07AM +1000, Steve Ball wrote:

The WXS module in libxml2-2.5.11 provides an interface
to schema-validate an instance document, given the schema
document as either a URL or in a memory buffer.
However, in my project I already have the schema document
as a xmlDocPtr object (ie. it is already parsed as an XML document).
At the moment my code serializes the schema document into
a memory buffer and then passes that buffer to
xmlSchemaNewMemParserCtxt.  This routine then re-parses the
document.

Accordingly, my RFE is to have a new API that accepts the
schema document as an xmlDocPtr.  Something like:

xmlSchemaParserCtxtPtr xmlSchemaNewDocParserCtxt   (xmlDocPtr doc);

The code would be fairly straight-forward, in fact almost
trivial.  I can do the implementation and submit it as a
patch if desired.


  Yep, should be trivial to add this entry point, I take patches :)
Still I'm a bit scared that you use the Schemas implementation, I
suppose it all depends on the schemas you actually use, if simple
enough you may not hit any bug.

Daniel


--
Steve Ball            |   XSLT Standard Library   | Training & Seminars
Zveno Pty Ltd         |     Web Tcl Complete      |   XML XSL Schemas
http://www.zveno.com/ |      TclXML TclDOM        | Tcl, Web Development
Steve Ball zveno com  +---------------------------+---------------------
Ph. +61 2 6242 4099   |   Mobile (0413) 594 462   | Fax +61 2 6242 4099
*** /tmp/libxml2-2.6.0/xmlschemas.c     Sun Oct 19 08:04:20 2003
--- xmlschemas.c        Wed Oct 29 16:59:33 2003
***************
*** 3184,3189 ****
--- 3184,3218 ----
  }
  
  /**
+  * xmlSchemaNewDocParserCtxt:
+  * @doc:  a preparsed document tree
+  *
+  * Create an XML Schemas parse context for that document.
+  * NB. The document may be modified during the parsing process.
+  *
+  * Returns the parser context or NULL in case of error
+  */
+ xmlSchemaParserCtxtPtr
+ xmlSchemaNewDocParserCtxt(xmlDocPtr doc)
+ {
+     xmlSchemaParserCtxtPtr ret;
+ 
+     if (doc == NULL)
+       return (NULL);
+ 
+     ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt));
+     if (ret == NULL) {
+       xmlSchemaPErrMemory(NULL, "allocating schema parser context",
+                         NULL);
+       return (NULL);
+     }
+     memset(ret, 0, sizeof(xmlSchemaParserCtxt));
+     ret->doc = doc;
+ 
+     return (ret);
+ }
+ 
+ /**
   * xmlSchemaFreeParserCtxt:
   * @ctxt:  the schema parser context
   *
***************
*** 4224,4229 ****
--- 4253,4260 ----
          }
          doc->URL = xmlStrdup(BAD_CAST "in_memory_buffer");
          ctxt->URL = xmlStrdup(BAD_CAST "in_memory_buffer");
+     } else if (ctxt->doc != NULL) {
+         doc = ctxt->doc;
      } else {
        xmlSchemaPErr(ctxt, NULL,
                      XML_SCHEMAP_NOTHING_TO_PARSE,
*** /tmp/libxml2-2.6.0/include/libxml/xmlschemas.h      Mon Sep 29 22:14:52 2003
--- include/libxml/xmlschemas.h Mon Oct 27 13:33:12 2003
***************
*** 77,82 ****
--- 77,84 ----
  XMLPUBFUN xmlSchemaParserCtxtPtr XMLCALL 
            xmlSchemaNewMemParserCtxt   (const char *buffer,
                                         int size);
+ XMLPUBFUN xmlSchemaParserCtxtPtr XMLCALL
+           xmlSchemaNewDocParserCtxt   (xmlDocPtr doc);
  XMLPUBFUN void XMLCALL                
            xmlSchemaFreeParserCtxt     (xmlSchemaParserCtxtPtr ctxt);
  XMLPUBFUN void XMLCALL                


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