1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

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> 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 * 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 \ xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c globals.c threads.c c14n.c \ catalog.c globals.c threads.c c14n.c \
xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.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 else
libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \ 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 \ 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 \ xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c globals.c threads.c c14n.c \ catalog.c globals.c threads.c c14n.c \
xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \ xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \
xmlreader.c relaxng.c dict.c xmlreader.c relaxng.c dict.c SAX2.c
endif endif
DEPS = $(top_builddir)/libxml2.la 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 static unsigned long
xmlDictComputeKey(xmlDictPtr dict, const xmlChar *name, int namelen) { xmlDictComputeKey(xmlDictPtr dict, const xmlChar *name, int namelen) {
unsigned long value = 0L; unsigned long value = 0L;
char ch;
int len = 0;
if (name == NULL) return(0); if (name == NULL) return(0);
value += 30 * (*name); value += 30 * (*name);

129
globals.c
View File

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

View File

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

View File

@ -119,9 +119,6 @@ void inithtmlDefaultSAXHandler (xmlSAXHandler *hdlr);
#ifdef LIBXML_DOCB_ENABLED #ifdef LIBXML_DOCB_ENABLED
void initdocbDefaultSAXHandler (xmlSAXHandler *hdlr); void initdocbDefaultSAXHandler (xmlSAXHandler *hdlr);
#endif #endif
void xmlDefaultSAXHandlerInit (void);
void htmlDefaultSAXHandlerInit (void);
void docbDefaultSAXHandlerInit (void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #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/parser.h>
#include <libxml/xmlerror.h> #include <libxml/xmlerror.h>
#include <libxml/SAX.h> #include <libxml/SAX2.h>
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -574,6 +574,7 @@ typedef int (*isStandaloneSAXFunc) (void *ctx);
* Returns 1 if true * Returns 1 if true
*/ */
typedef int (*hasInternalSubsetSAXFunc) (void *ctx); typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
/** /**
* hasExternalSubsetSAXFunc: * hasExternalSubsetSAXFunc:
* @ctx: the user data (XML parser context) * @ctx: the user data (XML parser context)
@ -584,6 +585,80 @@ typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
*/ */
typedef int (*hasExternalSubsetSAXFunc) (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 { struct _xmlSAXHandler {
internalSubsetSAXFunc internalSubset; internalSubsetSAXFunc internalSubset;
isStandaloneSAXFunc isStandalone; isStandaloneSAXFunc isStandalone;
@ -613,6 +688,11 @@ struct _xmlSAXHandler {
cdataBlockSAXFunc cdataBlock; cdataBlockSAXFunc cdataBlock;
externalSubsetSAXFunc externalSubset; externalSubsetSAXFunc externalSubset;
int initialized; 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, ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc,
BAD_CAST "fake", NULL, NULL); BAD_CAST "fake", NULL, NULL);
entityDecl(ctxt, name, XML_INTERNAL_GENERAL_ENTITY, xmlSAX2EntityDecl(ctxt, name, XML_INTERNAL_GENERAL_ENTITY,
NULL, NULL, value); NULL, NULL, value);
} }
} else { } else {
URI = xmlParseExternalID(ctxt, &literal, 1); URI = xmlParseExternalID(ctxt, &literal, 1);
@ -3775,9 +3775,9 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
if (ctxt->myDoc->intSubset == NULL) if (ctxt->myDoc->intSubset == NULL)
ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc, ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc,
BAD_CAST "fake", NULL, NULL); BAD_CAST "fake", NULL, NULL);
entityDecl(ctxt, name, xmlSAX2EntityDecl(ctxt, name,
XML_EXTERNAL_GENERAL_PARSED_ENTITY, XML_EXTERNAL_GENERAL_PARSED_ENTITY,
literal, URI, NULL); literal, URI, NULL);
} }
} }
} }
@ -3816,7 +3816,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
(ctxt->sax->getEntity != NULL)) (ctxt->sax->getEntity != NULL))
cur = ctxt->sax->getEntity(ctxt->userData, name); cur = ctxt->sax->getEntity(ctxt->userData, name);
if ((cur == NULL) && (ctxt->userData==ctxt)) { if ((cur == NULL) && (ctxt->userData==ctxt)) {
cur = getEntity(ctxt, name); cur = xmlSAX2GetEntity(ctxt, name);
} }
} }
if (cur != NULL) { if (cur != NULL) {
@ -5746,7 +5746,7 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
ent = xmlGetPredefinedEntity(name); ent = xmlGetPredefinedEntity(name);
if ((ctxt->wellFormed == 1 ) && (ent == NULL) && if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
(ctxt->userData==ctxt)) { (ctxt->userData==ctxt)) {
ent = getEntity(ctxt, name); ent = xmlSAX2GetEntity(ctxt, name);
} }
} }
/* /*
@ -5942,7 +5942,7 @@ xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) {
if (ent == NULL) if (ent == NULL)
ent = xmlGetPredefinedEntity(name); ent = xmlGetPredefinedEntity(name);
if ((ent == NULL) && (ctxt->userData==ctxt)) { if ((ent == NULL) && (ctxt->userData==ctxt)) {
ent = getEntity(ctxt, name); ent = xmlSAX2GetEntity(ctxt, name);
} }
} }
/* /*