From 33300b49f0801f5efe6363bd6b85b3bb5ace70fd Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 17 Apr 2003 09:09:19 +0000 Subject: [PATCH] augnemting the APIs, cleanups. cleanup bug #111005 added some missing * include/libxml/relaxng.h relaxng.c include/libxml/xmlreader.h xmlreader.c: augnemting the APIs, cleanups. * parser.c: cleanup bug #111005 * xmlIO.c: added some missing comments Daniel --- ChangeLog | 7 ++++ doc/libxml2-api.xml | 86 +++++++++++++++++++++++++++++++++++++- include/libxml/relaxng.h | 2 + include/libxml/xmlreader.h | 5 +++ parser.c | 4 -- python/libxml2class.txt | 8 ++++ relaxng.c | 48 ++++++++++++++++++--- xmlIO.c | 3 ++ xmlreader.c | 66 +++++++++++++++++++++++++++-- 9 files changed, 215 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa436154..2fcbd8ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Apr 17 11:06:28 CEST 2003 Daniel Veillard + + * include/libxml/relaxng.h relaxng.c include/libxml/xmlreader.h + xmlreader.c: augnemting the APIs, cleanups. + * parser.c: cleanup bug #111005 + * xmlIO.c: added some missing comments + Wed Apr 16 17:46:50 CEST 2003 Daniel Veillard * relaxng.c xmllint.c: more work on RelaxNG streaming validation diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml index 6ee16a60..e2238fc1 100644 --- a/doc/libxml2-api.xml +++ b/doc/libxml2-api.xml @@ -443,6 +443,7 @@ + @@ -1138,6 +1139,7 @@ + @@ -1163,6 +1165,8 @@ + + @@ -1182,6 +1186,7 @@ + @@ -1201,6 +1206,7 @@ + @@ -1214,6 +1220,7 @@ + @@ -1227,6 +1234,10 @@ + + + + @@ -1722,6 +1733,7 @@ + @@ -2527,6 +2539,7 @@ + @@ -2546,6 +2559,7 @@ + @@ -4456,6 +4470,16 @@ actually an xmlCharEncoding'/> + + If @to is NULL, this create first a new target state in the automata and then adds a transition from the @from state to the target state activated by the value of @token + + + + + + + + Makes that state a final state @@ -6898,8 +6922,8 @@ actually an xmlCharEncoding'/> This function is obsolete. Please see xmlURIFromPath in uri.c for a better solution. - - + + flushes and close the output I/O channel and free up all the associated resources @@ -7551,6 +7575,14 @@ actually an xmlCharEncoding'/> + + Push one input token in the execution context + + + + + + Free the structures associated to a regular expression evaulation context. @@ -7664,6 +7696,11 @@ actually an xmlCharEncoding'/> + + Create an XML RelaxNGs parser context for that document. Note: since the process of compiling a RelaxNG schemas modifies the document, the @doc parameter is duplicated internally. + + + Create an XML RelaxNGs parse context for that memory buffer expected to contain an XML RelaxNGs file. @@ -7707,6 +7744,34 @@ actually an xmlCharEncoding'/> + + Validate a full subtree when xmlRelaxNGValidatePushElement() returned 0 and the content of the node has been expanded. + + + + + + + Pop the element end from the RelaxNG validation stack. + + + + + + + check the CData parsed for validation in the current stack + + + + + + + Push a new element start on the RelaxNG validation stack. + + + + + @@ -8363,6 +8428,11 @@ actually an xmlCharEncoding'/> + + Retrieve the validity status from the parser context + + + The local name of the node. @@ -8483,6 +8553,18 @@ actually an xmlCharEncoding'/> + + Use RelaxNG to validate the document as it is processed. Activation is only possible before the first Read(). if @schema is NULL, then RelaxNG validation is desactivated. @ The @schema should not be freed until the reader is deallocated or its use has been deactivated. + + + + + + Use RelaxNG to validate the document as it is processed. Activation is only possible before the first Read(). if @rng is NULL, then RelaxNG validation is desactivated. + + + + Register a callback function that will be called on error and warnings. If @f is NULL, the default error and warning handlers are restored. diff --git a/include/libxml/relaxng.h b/include/libxml/relaxng.h index a21f92c2..46848cb8 100644 --- a/include/libxml/relaxng.h +++ b/include/libxml/relaxng.h @@ -81,6 +81,8 @@ typedef enum { xmlRelaxNGParserCtxtPtr xmlRelaxNGNewParserCtxt (const char *URL); xmlRelaxNGParserCtxtPtr xmlRelaxNGNewMemParserCtxt(const char *buffer, int size); +xmlRelaxNGParserCtxtPtr xmlRelaxNGNewDocParserCtxt(xmlDocPtr doc); + void xmlRelaxNGFreeParserCtxt (xmlRelaxNGParserCtxtPtr ctxt); void xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxtPtr ctxt, xmlRelaxNGValidityErrorFunc err, diff --git a/include/libxml/xmlreader.h b/include/libxml/xmlreader.h index 1ced8b85..99396b7c 100644 --- a/include/libxml/xmlreader.h +++ b/include/libxml/xmlreader.h @@ -11,6 +11,9 @@ #include #include +#ifdef LIBXML_SCHEMAS_ENABLED +#include +#endif #ifdef __cplusplus extern "C" { @@ -112,6 +115,8 @@ int xmlTextReaderIsValid (xmlTextReaderPtr reader); #ifdef LIBXML_SCHEMAS_ENABLED int xmlTextReaderRelaxNGValidate (xmlTextReaderPtr reader, const char *rng); +int xmlTextReaderRelaxNGSetSchema (xmlTextReaderPtr reader, + xmlRelaxNGPtr schema); #endif /* diff --git a/parser.c b/parser.c index 333e2735..5c7af3d1 100644 --- a/parser.c +++ b/parser.c @@ -10273,7 +10273,6 @@ xmlDocPtr xmlSAXParseEntity(xmlSAXHandlerPtr sax, const char *filename) { xmlDocPtr ret; xmlParserCtxtPtr ctxt; - char *directory = NULL; ctxt = xmlCreateFileParserCtxt(filename); if (ctxt == NULL) { @@ -10286,9 +10285,6 @@ xmlSAXParseEntity(xmlSAXHandlerPtr sax, const char *filename) { ctxt->userData = NULL; } - if ((ctxt->directory == NULL) && (directory == NULL)) - directory = xmlParserGetDirectory(filename); - xmlParseExtParsedEnt(ctxt); if (ctxt->wellFormed) diff --git a/python/libxml2class.txt b/python/libxml2class.txt index 950397d9..1e6808ac 100644 --- a/python/libxml2class.txt +++ b/python/libxml2class.txt @@ -474,7 +474,11 @@ Class xmlDoc(xmlNode) parameterEntity() # functions from module relaxng + relaxNGNewDocParserCtxt() relaxNGValidateDoc() + relaxNGValidateFullElement() + relaxNGValidatePopElement() + relaxNGValidatePushElement() # functions from module tree copyDoc() @@ -606,6 +610,7 @@ Class xmlTextReader(xmlTextReaderCore) HasValue() IsDefault() IsEmptyElement() + IsValid() LocalName() LookupNamespace() MoveToAttribute() @@ -627,6 +632,8 @@ Class xmlTextReader(xmlTextReaderCore) ReadOuterXml() ReadState() ReadString() + RelaxNGSetSchema() + RelaxNGValidate() SetParserProp() Value() XmlLang() @@ -654,6 +661,7 @@ Class relaxNgValidCtxt() # functions from module relaxng relaxNGFreeValidCtxt() + relaxNGValidatePushCData() Class xpathParserContext() # accessors context() diff --git a/relaxng.c b/relaxng.c index b7a0711b..b6961fd0 100644 --- a/relaxng.c +++ b/relaxng.c @@ -6509,6 +6509,39 @@ xmlRelaxNGNewMemParserCtxt(const char *buffer, int size) { return (ret); } +/** + * xmlRelaxNGNewDocParserCtxt: + * @doc: a preparsed document tree + * + * Create an XML RelaxNGs parser context for that document. + * Note: since the process of compiling a RelaxNG schemas modifies the + * document, the @doc parameter is duplicated internally. + * + * Returns the parser context or NULL in case of error + */ +xmlRelaxNGParserCtxtPtr +xmlRelaxNGNewDocParserCtxt(xmlDocPtr doc) { + xmlRelaxNGParserCtxtPtr ret; + xmlDocPtr copy; + + if (doc == NULL) + return(NULL); + copy = xmlCopyDoc(doc, 1); + if (copy == NULL) + return(NULL); + + ret = (xmlRelaxNGParserCtxtPtr) xmlMalloc(sizeof(xmlRelaxNGParserCtxt)); + if (ret == NULL) { + xmlGenericError(xmlGenericErrorContext, + "Failed to allocate new schama parser context\n"); + return (NULL); + } + memset(ret, 0, sizeof(xmlRelaxNGParserCtxt)); + ret->document = copy; + ret->userData = xmlGenericErrorContext; + return (ret); +} + /** * xmlRelaxNGFreeParserCtxt: * @ctxt: the schema parser context @@ -6522,7 +6555,7 @@ xmlRelaxNGFreeParserCtxt(xmlRelaxNGParserCtxtPtr ctxt) { if (ctxt->URL != NULL) xmlFree(ctxt->URL); if (ctxt->doc != NULL) - xmlFreeDoc(ctxt->document); + xmlFreeDoc(ctxt->doc); if (ctxt->interleaves != NULL) xmlHashFree(ctxt->interleaves, NULL); if (ctxt->documents != NULL) @@ -7159,6 +7192,8 @@ xmlRelaxNGParse(xmlRelaxNGParserCtxtPtr ctxt) } doc->URL = xmlStrdup(BAD_CAST "in_memory_buffer"); ctxt->URL = xmlStrdup(BAD_CAST "in_memory_buffer"); + } else if (ctxt->document != NULL) { + doc = ctxt->document; } else { if (ctxt->error != NULL) ctxt->error(ctxt->userData, @@ -7845,7 +7880,8 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec ATTRIBUTE_UNUSED, * element requires a full node, and -1 in case of error. */ int -xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxtPtr ctxt, xmlDocPtr doc, +xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxtPtr ctxt, + xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr elem) { int ret = 1; @@ -7924,7 +7960,8 @@ xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxtPtr ctxt, xmlDocPtr doc, */ int xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxtPtr ctxt, - const xmlChar * data, int len) + const xmlChar * data, + int len ATTRIBUTE_UNUSED) { int ret = 1; @@ -7945,7 +7982,7 @@ xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxtPtr ctxt, ret = xmlRegExecPushString(ctxt->elem, BAD_CAST "#text", ctxt); if (ret < 0) { - VALID_ERR2(XML_RELAXNG_ERR_TEXTWRONG, " TODO "); + VALID_ERR2(XML_RELAXNG_ERR_TEXTWRONG, BAD_CAST " TODO "); #ifdef DEBUG_PROGRESSIVE xmlGenericError(xmlGenericErrorContext, "CDATA failed\n"); #endif @@ -8013,7 +8050,8 @@ xmlRelaxNGValidatePopElement(xmlRelaxNGValidCtxtPtr ctxt, * returns 1 if no validation problem was found or -1 in case of error. */ int -xmlRelaxNGValidateFullElement(xmlRelaxNGValidCtxtPtr ctxt, xmlDocPtr doc, +xmlRelaxNGValidateFullElement(xmlRelaxNGValidCtxtPtr ctxt, + xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr elem) { int ret; xmlRelaxNGValidStatePtr state; diff --git a/xmlIO.c b/xmlIO.c index 82416f20..f137d66d 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -124,9 +124,12 @@ static int xmlOutputCallbackInitialized = 0; /** * xmlNormalizeWindowsPath: + * @path: the input file path * * This function is obsolete. Please see xmlURIFromPath in uri.c for * a better solution. + * + * Returns a canonicalized version of the path */ xmlChar * xmlNormalizeWindowsPath(const xmlChar *path) diff --git a/xmlreader.c b/xmlreader.c index 54a3b94e..73e5deb5 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -1031,7 +1031,7 @@ xmlTextReaderNext(xmlTextReaderPtr reader) { * string must be deallocated by the caller. */ xmlChar * -xmlTextReaderReadInnerXml(xmlTextReaderPtr reader) { +xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) { TODO return(NULL); } @@ -1047,7 +1047,7 @@ xmlTextReaderReadInnerXml(xmlTextReaderPtr reader) { * string must be deallocated by the caller. */ xmlChar * -xmlTextReaderReadOuterXml(xmlTextReaderPtr reader) { +xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) { TODO return(NULL); } @@ -1063,7 +1063,7 @@ xmlTextReaderReadOuterXml(xmlTextReaderPtr reader) { * The string must be deallocated by the caller. */ xmlChar * -xmlTextReaderReadString(xmlTextReaderPtr reader) { +xmlTextReaderReadString(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) { TODO return(NULL); } @@ -2501,6 +2501,58 @@ xmlTextReaderCurrentDoc(xmlTextReaderPtr reader) { return(reader->ctxt->myDoc); } +/** + * xmlTextReaderRelaxNGSetSchema: + * @reader: the xmlTextReaderPtr used + * @schema: a precompiled RelaxNG schema + * + * Use RelaxNG to validate the document as it is processed. + * Activation is only possible before the first Read(). + * if @schema is NULL, then RelaxNG validation is desactivated. + @ The @schema should not be freed until the reader is deallocated + * or its use has been deactivated. + * + * Returns 0 in case the RelaxNG validation could be (des)activated and + * -1 in case of error. + */ +int +xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, xmlRelaxNGPtr schema) { + if (schema == NULL) { + if (reader->rngSchemas != NULL) { + xmlRelaxNGFree(reader->rngSchemas); + reader->rngSchemas = NULL; + } + if (reader->rngValidCtxt != NULL) { + xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); + reader->rngValidCtxt = NULL; + } + return(0); + } + if (reader->mode != XML_TEXTREADER_MODE_INITIAL) + return(-1); + if (reader->rngSchemas != NULL) { + xmlRelaxNGFree(reader->rngSchemas); + reader->rngSchemas = NULL; + } + if (reader->rngValidCtxt != NULL) { + xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); + reader->rngValidCtxt = NULL; + } + reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema); + if (reader->rngValidCtxt == NULL) + return(-1); + if (reader->errorFunc != NULL) { + xmlRelaxNGSetValidErrors(reader->rngValidCtxt, + (xmlRelaxNGValidityErrorFunc)reader->errorFunc, + (xmlRelaxNGValidityWarningFunc) reader->errorFunc, + reader->errorFuncArg); + } + reader->rngValidErrors = 0; + reader->rngFullNode = NULL; + reader->validate = XML_TEXTREADER_VALIDATE_RNG; + return(0); +} + /** * xmlTextReaderRelaxNGValidate: * @reader: the xmlTextReaderPtr used @@ -2533,6 +2585,14 @@ xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng) { } if (reader->mode != XML_TEXTREADER_MODE_INITIAL) return(-1); + if (reader->rngSchemas != NULL) { + xmlRelaxNGFree(reader->rngSchemas); + reader->rngSchemas = NULL; + } + if (reader->rngValidCtxt != NULL) { + xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); + reader->rngValidCtxt = NULL; + } ctxt = xmlRelaxNGNewParserCtxt(rng); if (reader->errorFunc != NULL) { xmlRelaxNGSetParserErrors(ctxt,