Adding new version of the SAX interface, it's not there yet, currently

* Makefile.am SAX2.c include/libxml/Makefile.am include/libxml/SAX2.h:
  Adding new version of the SAX interface, it's not there yet,
  currently just preparing the work
* globals.c parser.c SAX.c include/libxml/SAX.h
  include/libxml/globals.h include/libxml/parser.h: doing some
  refactoring of the SAXv1 interfaces, obsoleting a bunch of them
  while keeping functionalities, preparing SAX2 integration.
* dict.c: small cleanup.
Daniel
This commit is contained in:
Daniel Veillard 2003-08-20 22:54:39 +00:00
parent e5984080ea
commit 1af9a41f24
12 changed files with 2465 additions and 1674 deletions

View File

@ -1,3 +1,14 @@
Thu Aug 21 00:50:32 CEST 2003 Daniel Veillard <daniel@veillard.com>
* Makefile.am SAX2.c include/libxml/Makefile.am include/libxml/SAX2.h:
Adding new version of the SAX interface, it's not there yet,
currently just preparing the work
* globals.c parser.c SAX.c include/libxml/SAX.h
include/libxml/globals.h include/libxml/parser.h: doing some
refactoring of the SAXv1 interfaces, obsoleting a bunch of them
while keeping functionalities, preparing SAX2 integration.
* dict.c: small cleanup.
Wed Aug 20 00:20:01 CEST 2003 Daniel Veillard <daniel@veillard.com>
* tree.c: fixes a small bug introduced in last commit and detected

View File

@ -26,7 +26,7 @@ libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c globals.c threads.c c14n.c \
xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \
triostr.c trio.c xmlreader.c relaxng.c dict.c
triostr.c trio.c xmlreader.c relaxng.c dict.c SAX2.c
else
libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
@ -34,7 +34,7 @@ libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c globals.c threads.c c14n.c \
xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \
xmlreader.c relaxng.c dict.c
xmlreader.c relaxng.c dict.c SAX2.c
endif
DEPS = $(top_builddir)/libxml2.la

1728
SAX.c

File diff suppressed because it is too large Load Diff

2036
SAX2.c Normal file

File diff suppressed because it is too large Load Diff

2
dict.c
View File

@ -61,8 +61,6 @@ struct _xmlDict {
static unsigned long
xmlDictComputeKey(xmlDictPtr dict, const xmlChar *name, int namelen) {
unsigned long value = 0L;
char ch;
int len = 0;
if (name == NULL) return(0);
value += 30 * (*name);

129
globals.c
View File

@ -331,34 +331,38 @@ int xmlSaveNoEmptyTagsThrDef = 0;
* Default handler for XML, builds the DOM tree
*/
xmlSAXHandler xmlDefaultSAXHandler = {
internalSubset,
isStandalone,
hasInternalSubset,
hasExternalSubset,
resolveEntity,
getEntity,
entityDecl,
notationDecl,
attributeDecl,
elementDecl,
unparsedEntityDecl,
setDocumentLocator,
startDocument,
endDocument,
startElement,
endElement,
reference,
characters,
characters,
processingInstruction,
comment,
xmlSAX2InternalSubset,
xmlSAX2IsStandalone,
xmlSAX2HasInternalSubset,
xmlSAX2HasExternalSubset,
xmlSAX2ResolveEntity,
xmlSAX2GetEntity,
xmlSAX2EntityDecl,
xmlSAX2NotationDecl,
xmlSAX2AttributeDecl,
xmlSAX2ElementDecl,
xmlSAX2UnparsedEntityDecl,
xmlSAX2SetDocumentLocator,
xmlSAX2StartDocument,
xmlSAX2EndDocument,
xmlSAX2StartElement,
xmlSAX2EndElement,
xmlSAX2Reference,
xmlSAX2Characters,
xmlSAX2Characters,
xmlSAX2ProcessingInstruction,
xmlSAX2Comment,
xmlParserWarning,
xmlParserError,
xmlParserError,
getParameterEntity,
cdataBlock,
externalSubset,
0
xmlSAX2GetParameterEntity,
xmlSAX2CDataBlock,
xmlSAX2ExternalSubset,
0,
NULL,
NULL,
NULL,
NULL
};
/**
@ -368,7 +372,10 @@ xmlSAXHandler xmlDefaultSAXHandler = {
* { getPublicId, getSystemId, getLineNumber, getColumnNumber}
*/
xmlSAXLocator xmlDefaultSAXLocator = {
getPublicId, getSystemId, getLineNumber, getColumnNumber
xmlSAX2GetPublicId,
xmlSAX2GetSystemId,
xmlSAX2GetLineNumber,
xmlSAX2GetColumnNumber
};
#ifdef LIBXML_HTML_ENABLED
@ -378,34 +385,38 @@ xmlSAXLocator xmlDefaultSAXLocator = {
* Default handler for HTML, builds the DOM tree
*/
xmlSAXHandler htmlDefaultSAXHandler = {
internalSubset,
xmlSAX2InternalSubset,
NULL,
NULL,
NULL,
NULL,
getEntity,
xmlSAX2GetEntity,
NULL,
NULL,
NULL,
NULL,
NULL,
setDocumentLocator,
startDocument,
endDocument,
startElement,
endElement,
xmlSAX2SetDocumentLocator,
xmlSAX2StartDocument,
xmlSAX2EndDocument,
xmlSAX2StartElement,
xmlSAX2EndElement,
NULL,
characters,
ignorableWhitespace,
xmlSAX2Characters,
xmlSAX2IgnorableWhitespace,
NULL,
comment,
xmlSAX2Comment,
xmlParserWarning,
xmlParserError,
xmlParserError,
getParameterEntity,
cdataBlock,
xmlSAX2GetParameterEntity,
xmlSAX2CDataBlock,
NULL,
0
0,
NULL,
NULL,
NULL,
NULL
};
#endif /* LIBXML_HTML_ENABLED */
@ -416,34 +427,38 @@ xmlSAXHandler htmlDefaultSAXHandler = {
* Default handler for SGML DocBook, builds the DOM tree
*/
xmlSAXHandler docbDefaultSAXHandler = {
internalSubset,
isStandalone,
hasInternalSubset,
hasExternalSubset,
resolveEntity,
getEntity,
entityDecl,
xmlSAX2InternalSubset,
xmlSAX2IsStandalone,
xmlSAX2HasInternalSubset,
xmlSAX2HasExternalSubset,
xmlSAX2ResolveEntity,
xmlSAX2GetEntity,
xmlSAX2EntityDecl,
NULL,
NULL,
NULL,
NULL,
setDocumentLocator,
startDocument,
endDocument,
startElement,
endElement,
reference,
characters,
ignorableWhitespace,
xmlSAX2SetDocumentLocator,
xmlSAX2StartDocument,
xmlSAX2EndDocument,
xmlSAX2StartElement,
xmlSAX2EndElement,
xmlSAX2Reference,
xmlSAX2Characters,
xmlSAX2IgnorableWhitespace,
NULL,
comment,
xmlSAX2Comment,
xmlParserWarning,
xmlParserError,
xmlParserError,
getParameterEntity,
xmlSAX2GetParameterEntity,
NULL,
NULL,
0
0,
NULL,
NULL,
NULL,
NULL
};
#endif /* LIBXML_DOCB_ENABLED */

View File

@ -40,7 +40,8 @@ xmlinc_HEADERS = \
xmlunicode.h \
xmlreader.h \
relaxng.h \
dict.h
dict.h \
SAX2.h
install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(xmlincdir)

View File

@ -119,9 +119,6 @@ void inithtmlDefaultSAXHandler (xmlSAXHandler *hdlr);
#ifdef LIBXML_DOCB_ENABLED
void initdocbDefaultSAXHandler (xmlSAXHandler *hdlr);
#endif
void xmlDefaultSAXHandlerInit (void);
void htmlDefaultSAXHandlerInit (void);
void docbDefaultSAXHandlerInit (void);
#ifdef __cplusplus
}
#endif

125
include/libxml/SAX2.h Normal file
View File

@ -0,0 +1,125 @@
/*
* SAX.h : Default SAX2 handler interfaces to build a tree.
*
* See Copyright for the status of this software.
*
* Daniel Veillard <daniel@veillard.com>
*/
#ifndef __XML_SAX2_H__
#define __XML_SAX2_H__
#include <stdio.h>
#include <stdlib.h>
#include <libxml/parser.h>
#include <libxml/xlink.h>
#ifdef __cplusplus
extern "C" {
#endif
const xmlChar * xmlSAX2GetPublicId (void *ctx);
const xmlChar * xmlSAX2GetSystemId (void *ctx);
void xmlSAX2SetDocumentLocator (void *ctx,
xmlSAXLocatorPtr loc);
int xmlSAX2GetLineNumber (void *ctx);
int xmlSAX2GetColumnNumber (void *ctx);
int xmlSAX2IsStandalone (void *ctx);
int xmlSAX2HasInternalSubset (void *ctx);
int xmlSAX2HasExternalSubset (void *ctx);
void xmlSAX2InternalSubset (void *ctx,
const xmlChar *name,
const xmlChar *ExternalID,
const xmlChar *SystemID);
void xmlSAX2ExternalSubset (void *ctx,
const xmlChar *name,
const xmlChar *ExternalID,
const xmlChar *SystemID);
xmlEntityPtr xmlSAX2GetEntity (void *ctx,
const xmlChar *name);
xmlEntityPtr xmlSAX2GetParameterEntity (void *ctx,
const xmlChar *name);
xmlParserInputPtr xmlSAX2ResolveEntity (void *ctx,
const xmlChar *publicId,
const xmlChar *systemId);
void xmlSAX2EntityDecl (void *ctx,
const xmlChar *name,
int type,
const xmlChar *publicId,
const xmlChar *systemId,
xmlChar *content);
void xmlSAX2AttributeDecl (void *ctx,
const xmlChar *elem,
const xmlChar *fullname,
int type,
int def,
const xmlChar *defaultValue,
xmlEnumerationPtr tree);
void xmlSAX2ElementDecl (void *ctx,
const xmlChar *name,
int type,
xmlElementContentPtr content);
void xmlSAX2NotationDecl (void *ctx,
const xmlChar *name,
const xmlChar *publicId,
const xmlChar *systemId);
void xmlSAX2UnparsedEntityDecl (void *ctx,
const xmlChar *name,
const xmlChar *publicId,
const xmlChar *systemId,
const xmlChar *notationName);
void xmlSAX2StartDocument (void *ctx);
void xmlSAX2EndDocument (void *ctx);
void xmlSAX2StartElement (void *ctx,
const xmlChar *fullname,
const xmlChar **atts);
void xmlSAX2EndElement (void *ctx,
const xmlChar *name);
void xmlSAX2Reference (void *ctx,
const xmlChar *name);
void xmlSAX2Characters (void *ctx,
const xmlChar *ch,
int len);
void xmlSAX2IgnorableWhitespace (void *ctx,
const xmlChar *ch,
int len);
void xmlSAX2ProcessingInstruction (void *ctx,
const xmlChar *target,
const xmlChar *data);
void xmlSAX2GlobalNamespace (void *ctx,
const xmlChar *href,
const xmlChar *prefix);
void xmlSAX2SetNamespace (void *ctx,
const xmlChar *name);
xmlNsPtr xmlSAX2GetNamespace (void *ctx);
int xmlSAX2CheckNamespace (void *ctx,
xmlChar *nameSpace);
void xmlSAX2NamespaceDecl (void *ctx,
const xmlChar *href,
const xmlChar *prefix);
void xmlSAX2Comment (void *ctx,
const xmlChar *value);
void xmlSAX2CDataBlock (void *ctx,
const xmlChar *value,
int len);
void xmlSAX2InitDefaultSAXHandler (xmlSAXHandler *hdlr,
int warning);
#ifdef LIBXML_HTML_ENABLED
void xmlSAX2InitHtmlDefaultSAXHandler(xmlSAXHandler *hdlr);
#endif
#ifdef LIBXML_DOCB_ENABLED
void xmlSAX2InitDocbDefaultSAXHandler(xmlSAXHandler *hdlr);
#endif
void xmlDefaultSAXHandlerInit (void);
void htmlDefaultSAXHandlerInit (void);
void docbDefaultSAXHandlerInit (void);
#ifdef __cplusplus
}
#endif
#endif /* __XML_SAX2_H__ */

View File

@ -15,7 +15,7 @@
#include <libxml/parser.h>
#include <libxml/xmlerror.h>
#include <libxml/SAX.h>
#include <libxml/SAX2.h>
#include <libxml/xmlmemory.h>
#ifdef __cplusplus

View File

@ -574,6 +574,7 @@ typedef int (*isStandaloneSAXFunc) (void *ctx);
* Returns 1 if true
*/
typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
/**
* hasExternalSubsetSAXFunc:
* @ctx: the user data (XML parser context)
@ -584,6 +585,80 @@ typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
*/
typedef int (*hasExternalSubsetSAXFunc) (void *ctx);
/************************************************************************
* *
* The SAX version 2 API extensions *
* *
************************************************************************/
/**
* XML_SAX2_MAGIC:
*
* Special constant found in SAX2 blocks initialized fields
*/
#define XML_SAX2_MAGIC 0xDEEDBEAF
/**
* startElementNsSAX2Func:
* @ctx: the user data (XML parser context)
* @localname: the local name of the element
* @prefix: the element namespace prefix if available
* @URI: the element namespace name if available
* @nb_namespaces: number of namespace definitions on that node
* @namespaces: pointer to the array of prefix/URI pairs namespace definitions
* @nb_attributes: the number of attributes on that node
*
* SAX2 callback when an element start has been detected by the parser.
* It provides the namespace informations for the element, as well as
* the new namespace declarations on the element.
* The number of attributes is given in this callback but the attributes
* themselves will be provided as separate callbacks.
*/
typedef void (*startElementNsSAX2Func) (void *ctx,
const xmlChar *localname,
const xmlChar *prefix,
const xmlChar *URI,
int nb_namespaces,
const xmlChar **namespaces,
int nb_attributes);
/**
* endElementNsSAX2Func:
* @ctx: the user data (XML parser context)
* @localname: the local name of the element
* @prefix: the element namespace prefix if available
* @URI: the element namespace name if available
*
* SAX2 callback when an element end has been detected by the parser.
* It provides the namespace informations for the element.
*/
typedef void (*endElementNsSAX2Func) (void *ctx,
const xmlChar *localname,
const xmlChar *prefix,
const xmlChar *URI);
/**
* attributeNsSAX2Func:
* @ctx: the user data (XML parser context)
* @localname: the local name of the attribute
* @prefix: the attribute namespace prefix if available
* @URI: the attribute namespace name if available
* @value: pointer to the attribute value string
* @valuelen: lenght of the attribute value string in bytes
*
* SAX2 callback when an attribute has been detected by the parser.
* It provides the namespace informations for the attribute, as well as
* the value of the attribute (note that @value may not be zero terminated
* and use of the @valuelen is needed to find the value end).
*/
typedef void (*attributeNsSAX2Func) (void *ctx,
const xmlChar *localname,
const xmlChar *prefix,
const xmlChar *URI,
const xmlChar *value,
int valuelen);
struct _xmlSAXHandler {
internalSubsetSAXFunc internalSubset;
isStandaloneSAXFunc isStandalone;
@ -613,6 +688,11 @@ struct _xmlSAXHandler {
cdataBlockSAXFunc cdataBlock;
externalSubsetSAXFunc externalSubset;
int initialized;
/* The following fields are extensions available only on version 2 */
void *_private;
startElementNsSAX2Func startElementNs;
endElementNsSAX2Func endElementNs;
attributeNsSAX2Func attributeNs;
};
/**

View File

@ -3682,8 +3682,8 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc,
BAD_CAST "fake", NULL, NULL);
entityDecl(ctxt, name, XML_INTERNAL_GENERAL_ENTITY,
NULL, NULL, value);
xmlSAX2EntityDecl(ctxt, name, XML_INTERNAL_GENERAL_ENTITY,
NULL, NULL, value);
}
} else {
URI = xmlParseExternalID(ctxt, &literal, 1);
@ -3775,9 +3775,9 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
if (ctxt->myDoc->intSubset == NULL)
ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc,
BAD_CAST "fake", NULL, NULL);
entityDecl(ctxt, name,
XML_EXTERNAL_GENERAL_PARSED_ENTITY,
literal, URI, NULL);
xmlSAX2EntityDecl(ctxt, name,
XML_EXTERNAL_GENERAL_PARSED_ENTITY,
literal, URI, NULL);
}
}
}
@ -3816,7 +3816,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
(ctxt->sax->getEntity != NULL))
cur = ctxt->sax->getEntity(ctxt->userData, name);
if ((cur == NULL) && (ctxt->userData==ctxt)) {
cur = getEntity(ctxt, name);
cur = xmlSAX2GetEntity(ctxt, name);
}
}
if (cur != NULL) {
@ -5746,7 +5746,7 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
ent = xmlGetPredefinedEntity(name);
if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
(ctxt->userData==ctxt)) {
ent = getEntity(ctxt, name);
ent = xmlSAX2GetEntity(ctxt, name);
}
}
/*
@ -5942,7 +5942,7 @@ xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) {
if (ent == NULL)
ent = xmlGetPredefinedEntity(name);
if ((ent == NULL) && (ctxt->userData==ctxt)) {
ent = getEntity(ctxt, name);
ent = xmlSAX2GetEntity(ctxt, name);
}
}
/*