better SAX interfaces. preparing for 1.7.2, Daniel.

This commit is contained in:
Daniel Veillard 1999-09-26 11:31:02 +00:00
parent ca8484739b
commit 7a66ee6bd0
7 changed files with 166 additions and 64 deletions

View File

@ -1,13 +1,21 @@
Fri Sep 24 16:01:01 CEST 1999
Sun Sep 26 13:16:54 CEST 1999 Daniel Veillard <Daniel.Veillard@w3.org>
* parser.[ch] : added xmlSAXUserParseFile() and xmlSAXUserParseMemory()
better SAX interfaces.
* testSAX.c: uses the new SAX routine, avoid fetching any remote
entity.
* configure.in: 1.7.2
Fri Sep 24 16:01:01 CEST 1999 Daniel Veillard <Daniel.Veillard@w3.org>
* libxml.spec.in: fixed the URL
* doc/xml.html: improved the documentation front-end
Fri Sep 24 01:06:36 CEST 1999
Fri Sep 24 01:06:36 CEST 1999 Daniel Veillard <Daniel.Veillard@w3.org>
* nanohttp.c: conditionned references to snprintf with HAVE_SNPRINTF
Fri Sep 24 00:15:58 CEST 1999
Fri Sep 24 00:15:58 CEST 1999 Daniel Veillard <Daniel.Veillard@w3.org>
* libxml.spec.in: fixed the alpha compile problem
* parser.[ch]: changed errno to errNo in the parser context :-(

View File

@ -5,7 +5,7 @@ AM_CONFIG_HEADER(config.h)
LIBXML_MAJOR_VERSION=1
LIBXML_MINOR_VERSION=7
LIBXML_MICRO_VERSION=1
LIBXML_MICRO_VERSION=2
LIBXML_VERSION=$LIBXML_MAJOR_VERSION.$LIBXML_MINOR_VERSION.$LIBXML_MICRO_VERSION
LIBXML_VERSION_INFO=`expr $LIBXML_MAJOR_VERSION + $LIBXML_MINOR_VERSION`:$LIBXML_MICRO_VERSION:$LIBXML_MINOR_VERSION

View File

@ -272,10 +272,10 @@ int xmlParserInputGrow (xmlParserInputPtr in,
/**
* xmlChar handling
*/
xmlChar * xmlStrdup (const xmlChar *cur);
xmlChar * xmlStrndup (const xmlChar *cur,
xmlChar * xmlStrdup (const xmlChar *cur);
xmlChar * xmlStrndup (const xmlChar *cur,
int len);
xmlChar * xmlStrsub (const xmlChar *str,
xmlChar * xmlStrsub (const xmlChar *str,
int start,
int len);
const xmlChar * xmlStrchr (const xmlChar *str,
@ -288,9 +288,9 @@ int xmlStrncmp (const xmlChar *str1,
const xmlChar *str2,
int len);
int xmlStrlen (const xmlChar *str);
xmlChar * xmlStrcat (xmlChar *cur,
xmlChar * xmlStrcat (xmlChar *cur,
const xmlChar *add);
xmlChar * xmlStrncat (xmlChar *cur,
xmlChar * xmlStrncat (xmlChar *cur,
const xmlChar *add,
int len);
@ -318,6 +318,13 @@ int xmlParseDocument (xmlParserCtxtPtr ctxt);
xmlDocPtr xmlSAXParseDoc (xmlSAXHandlerPtr sax,
xmlChar *cur,
int recovery);
int xmlSAXUserParseFile (xmlSAXHandlerPtr sax,
void *user_data,
const char *filename);
int xmlSAXUserParseMemory (xmlSAXHandlerPtr sax,
void *user_data,
char *buffer,
int size);
xmlDocPtr xmlSAXParseMemory (xmlSAXHandlerPtr sax,
char *buffer,
int size,

View File

@ -6474,6 +6474,83 @@ xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const xmlChar* buffer,
inputPush(ctxt, input);
}
/**
* xmlSAXUserParseFile:
* @sax: a SAX handler
* @user_data: The user data returned on SAX callbacks
* @filename: a file name
*
* parse an XML file and call the given SAX handler routines.
* Automatic support for ZLIB/Compress compressed document is provided
*
* Returns 0 in case of success or a error number otherwise
*/
int xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data,
const char *filename) {
int ret = 0;
xmlParserCtxtPtr ctxt;
ctxt = xmlCreateFileParserCtxt(filename);
if (ctxt == NULL) return -1;
ctxt->sax = sax;
ctxt->userData = user_data;
xmlParseDocument(ctxt);
if (ctxt->wellFormed)
ret = 0;
else {
if (ctxt->errNo != 0)
ret = ctxt->errNo;
else
ret = -1;
}
if (sax != NULL)
ctxt->sax = NULL;
xmlFreeParserCtxt(ctxt);
return ret;
}
/**
* xmlSAXUserParseMemory:
* @sax: a SAX handler
* @user_data: The user data returned on SAX callbacks
* @buffer: an in-memory XML document input
* @size: the lenght of the XML document in bytes
*
* A better SAX parsing routine.
* parse an XML in-memory buffer and call the given SAX handler routines.
*
* Returns 0 in case of success or a error number otherwise
*/
int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void *user_data,
char *buffer, int size) {
int ret = 0;
xmlParserCtxtPtr ctxt;
ctxt = xmlCreateMemoryParserCtxt(buffer, size);
if (ctxt == NULL) return -1;
ctxt->sax = sax;
ctxt->userData = user_data;
xmlParseDocument(ctxt);
if (ctxt->wellFormed)
ret = 0;
else {
if (ctxt->errNo != 0)
ret = ctxt->errNo;
else
ret = -1;
}
if (sax != NULL)
ctxt->sax = NULL;
xmlFreeParserCtxt(ctxt);
return ret;
}
/************************************************************************
* *

View File

@ -272,10 +272,10 @@ int xmlParserInputGrow (xmlParserInputPtr in,
/**
* xmlChar handling
*/
xmlChar * xmlStrdup (const xmlChar *cur);
xmlChar * xmlStrndup (const xmlChar *cur,
xmlChar * xmlStrdup (const xmlChar *cur);
xmlChar * xmlStrndup (const xmlChar *cur,
int len);
xmlChar * xmlStrsub (const xmlChar *str,
xmlChar * xmlStrsub (const xmlChar *str,
int start,
int len);
const xmlChar * xmlStrchr (const xmlChar *str,
@ -288,9 +288,9 @@ int xmlStrncmp (const xmlChar *str1,
const xmlChar *str2,
int len);
int xmlStrlen (const xmlChar *str);
xmlChar * xmlStrcat (xmlChar *cur,
xmlChar * xmlStrcat (xmlChar *cur,
const xmlChar *add);
xmlChar * xmlStrncat (xmlChar *cur,
xmlChar * xmlStrncat (xmlChar *cur,
const xmlChar *add,
int len);
@ -318,6 +318,13 @@ int xmlParseDocument (xmlParserCtxtPtr ctxt);
xmlDocPtr xmlSAXParseDoc (xmlSAXHandlerPtr sax,
xmlChar *cur,
int recovery);
int xmlSAXUserParseFile (xmlSAXHandlerPtr sax,
void *user_data,
const char *filename);
int xmlSAXUserParseMemory (xmlSAXHandlerPtr sax,
void *user_data,
char *buffer,
int size);
xmlDocPtr xmlSAXParseMemory (xmlSAXHandlerPtr sax,
char *buffer,
int size,

View File

@ -32,6 +32,9 @@
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "parser.h"
@ -77,7 +80,7 @@ extern xmlSAXHandlerPtr debugSAXHandler;
/*
* Note: there is a couple of errors introduced on purpose.
*/
static xmlChar buffer[] =
static char buffer[] =
"<?xml version=\"1.0\"?>\n\
<?xml:namespace ns = \"http://www.ietf.org/standards/dav/\" prefix = \"D\"?>\n\
<?xml:namespace ns = \"http://www.w3.com/standards/z39.50/\" prefix = \"Z\"?>\n\
@ -158,17 +161,19 @@ void
internalSubsetDebug(void *ctx, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID)
{
xmlDtdPtr externalSubset;
/* xmlDtdPtr externalSubset; */
fprintf(stdout, "SAX.internalSubset(%s, %s, %s)\n",
name, ExternalID, SystemID);
/***********
if ((ExternalID != NULL) || (SystemID != NULL)) {
externalSubset = xmlParseDTD(ExternalID, SystemID);
if (externalSubset != NULL) {
xmlFreeDtd(externalSubset);
}
}
***********/
}
/**
@ -188,7 +193,7 @@ internalSubsetDebug(void *ctx, const xmlChar *name,
xmlParserInputPtr
resolveEntityDebug(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
/* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
fprintf(stdout, "SAX.resolveEntity(");
@ -200,9 +205,11 @@ resolveEntityDebug(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
fprintf(stdout, ", %s)\n", (char *)systemId);
else
fprintf(stdout, ", )\n");
/*********
if (systemId != NULL) {
return(xmlNewInputFromFile(ctxt, (char *) systemId));
}
*********/
return(NULL);
}
@ -579,46 +586,42 @@ xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
************************************************************************/
void parseAndPrintFile(char *filename) {
xmlDocPtr doc;
int res;
/*
* Empty callbacks for checking
*/
doc = xmlSAXParseFile(emptySAXHandler, filename, 0);
if (doc != NULL) {
fprintf(stdout, "xmlSAXParseFile returned non-NULL\n");
xmlDocDump(stdout, doc);
res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
if (res != 0) {
fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
}
/*
* Debug callback
*/
doc = xmlSAXParseFile(debugSAXHandler, filename, 0);
if (doc != NULL) {
fprintf(stderr, "xmlSAXParseFile returned non-NULL\n");
xmlDocDump(stdout, doc);
res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
if (res != 0) {
fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
}
}
void parseAndPrintBuffer(xmlChar *buf) {
xmlDocPtr doc;
void parseAndPrintBuffer(char *buf) {
int res;
/*
* Empty callbacks for checking
*/
doc = xmlSAXParseDoc(emptySAXHandler, buf, 0);
if (doc != NULL) {
fprintf(stderr, "xmlSAXParseDoc returned non-NULL\n");
xmlDocDump(stdout, doc);
res = xmlSAXUserParseMemory(emptySAXHandler, NULL, buf, strlen(buf));
if (res != 0) {
fprintf(stdout, "xmlSAXUserParseMemory returned error %d\n", res);
}
/*
* Debug callback
*/
doc = xmlSAXParseDoc(debugSAXHandler, buf, 0);
if (doc != NULL) {
fprintf(stderr, "xmlSAXParseDoc returned non-NULL\n");
xmlDocDump(stdout, doc);
res = xmlSAXUserParseMemory(debugSAXHandler, NULL, buf, strlen(buf));
if (res != 0) {
fprintf(stdout, "xmlSAXUserParseMemory returned error %d\n", res);
}
}

View File

@ -8,16 +8,16 @@ typedef enum {
XML_ERR_INTERNAL_ERROR,
XML_ERR_NO_MEMORY,
XML_ERR_DOCUMENT_START,
XML_ERR_DOCUMENT_START, /* 3 */
XML_ERR_DOCUMENT_EMPTY,
XML_ERR_DOCUMENT_END,
XML_ERR_INVALID_HEX_CHARREF,
XML_ERR_INVALID_HEX_CHARREF, /* 6 */
XML_ERR_INVALID_DEC_CHARREF,
XML_ERR_INVALID_CHARREF,
XML_ERR_INVALID_CHAR,
XML_ERR_CHARREF_AT_EOF,
XML_ERR_CHARREF_AT_EOF, /* 10 */
XML_ERR_CHARREF_IN_PROLOG,
XML_ERR_CHARREF_IN_EPILOG,
XML_ERR_CHARREF_IN_DTD,
@ -30,70 +30,70 @@ typedef enum {
XML_ERR_PEREF_IN_EPILOG,
XML_ERR_PEREF_IN_INT_SUBSET,
XML_ERR_ENTITYREF_NO_NAME,
XML_ERR_ENTITYREF_NO_NAME, /* 22 */
XML_ERR_ENTITYREF_SEMICOL_MISSING,
XML_ERR_PEREF_NO_NAME,
XML_ERR_PEREF_NO_NAME, /* 24 */
XML_ERR_PEREF_SEMICOL_MISSING,
XML_ERR_UNDECLARED_ENTITY,
XML_ERR_UNDECLARED_ENTITY, /* 26 */
XML_WAR_UNDECLARED_ENTITY,
XML_ERR_UNPARSED_ENTITY,
XML_ERR_ENTITY_IS_EXTERNAL,
XML_ERR_ENTITY_IS_PARAMETER,
XML_ERR_UNKNOWN_ENCODING,
XML_ERR_UNKNOWN_ENCODING, /* 31 */
XML_ERR_UNSUPPORTED_ENCODING,
XML_ERR_STRING_NOT_STARTED,
XML_ERR_STRING_NOT_STARTED, /* 33 */
XML_ERR_STRING_NOT_CLOSED,
XML_ERR_NS_DECL_ERROR,
XML_ERR_ENTITY_NOT_STARTED,
XML_ERR_ENTITY_NOT_STARTED, /* 36 */
XML_ERR_ENTITY_NOT_FINISHED,
XML_ERR_LT_IN_ATTRIBUTE,
XML_ERR_LT_IN_ATTRIBUTE, /* 38 */
XML_ERR_ATTRIBUTE_NOT_STARTED,
XML_ERR_ATTRIBUTE_NOT_FINISHED,
XML_ERR_ATTRIBUTE_WITHOUT_VALUE,
XML_ERR_ATTRIBUTE_REDEFINED,
XML_ERR_LITERAL_NOT_STARTED,
XML_ERR_LITERAL_NOT_STARTED, /* 43 */
XML_ERR_LITERAL_NOT_FINISHED,
XML_ERR_COMMENT_NOT_FINISHED,
XML_ERR_COMMENT_NOT_FINISHED, /* 45 */
XML_ERR_PI_NOT_STARTED,
XML_ERR_PI_NOT_STARTED, /* 47 */
XML_ERR_PI_NOT_FINISHED,
XML_ERR_NOTATION_NOT_STARTED,
XML_ERR_NOTATION_NOT_STARTED, /* 49 */
XML_ERR_NOTATION_NOT_FINISHED,
XML_ERR_ATTLIST_NOT_STARTED,
XML_ERR_ATTLIST_NOT_STARTED, /* 51 */
XML_ERR_ATTLIST_NOT_FINISHED,
XML_ERR_MIXED_NOT_STARTED,
XML_ERR_MIXED_NOT_STARTED, /* 53 */
XML_ERR_MIXED_NOT_FINISHED,
XML_ERR_ELEMCONTENT_NOT_STARTED,
XML_ERR_ELEMCONTENT_NOT_STARTED, /* 55 */
XML_ERR_ELEMCONTENT_NOT_FINISHED,
XML_ERR_XMLDECL_NOT_STARTED,
XML_ERR_XMLDECL_NOT_STARTED, /* 57 */
XML_ERR_XMLDECL_NOT_FINISHED,
XML_ERR_CONDSEC_NOT_STARTED,
XML_ERR_CONDSEC_NOT_STARTED, /* 59 */
XML_ERR_CONDSEC_NOT_FINISHED,
XML_ERR_EXT_SUBSET_NOT_FINISHED,
XML_ERR_EXT_SUBSET_NOT_FINISHED, /* 61 */
XML_ERR_DOCTYPE_NOT_FINISHED,
XML_ERR_DOCTYPE_NOT_FINISHED, /* 62 */
XML_ERR_MISPLACED_CDATA_END,
XML_ERR_MISPLACED_CDATA_END, /* 63 */
XML_ERR_CDATA_NOT_FINISHED,
XML_ERR_RESERVED_XML_NAME,
XML_ERR_RESERVED_XML_NAME, /* 65 */
XML_ERR_SPACE_REQUIRED,
XML_ERR_SPACE_REQUIRED, /* 66 */
XML_ERR_SEPARATOR_REQUIRED,
XML_ERR_NMTOKEN_REQUIRED,
XML_ERR_NAME_REQUIRED,
@ -105,14 +105,14 @@ typedef enum {
XML_ERR_LTSLASH_REQUIRED,
XML_ERR_EQUAL_REQUIRED,
XML_ERR_TAG_NAME_MISMATCH,
XML_ERR_TAG_NAME_MISMATCH, /* 77 */
XML_ERR_TAG_NOT_FINISED,
XML_ERR_STANDALONE_VALUE,
XML_ERR_STANDALONE_VALUE, /* 79 */
XML_ERR_ENCODING_NAME,
XML_ERR_ENCODING_NAME, /* 80 */
XML_ERR_HYPHEN_IN_COMMENT
XML_ERR_HYPHEN_IN_COMMENT /* 81 */
}xmlParserErrors;