Added start/endDoctypeDeclHandlers

This commit is contained in:
James Clark 1999-07-28 09:34:18 +00:00
parent 17c6938a36
commit ab5acbf509
4 changed files with 64 additions and 6 deletions

View file

@ -9,7 +9,7 @@
<H1>expat - XML Parser Toolkit</H1>
<H3>Version 19990709</H3>
<H3>Version 19990728</H3>
<P>Copyright (c) 1998, 1999 James Clark. Expat is subject to the <A
HREF="http://www.mozilla.org/NPL/NPL-1_1Final.html">Mozilla Public

View file

@ -300,6 +300,8 @@ typedef struct {
XML_StartCdataSectionHandler m_startCdataSectionHandler;
XML_EndCdataSectionHandler m_endCdataSectionHandler;
XML_DefaultHandler m_defaultHandler;
XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler;
XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler;
XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler;
XML_NotationDeclHandler m_notationDeclHandler;
XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler;
@ -364,6 +366,8 @@ typedef struct {
#define startCdataSectionHandler (((Parser *)parser)->m_startCdataSectionHandler)
#define endCdataSectionHandler (((Parser *)parser)->m_endCdataSectionHandler)
#define defaultHandler (((Parser *)parser)->m_defaultHandler)
#define startDoctypeDeclHandler (((Parser *)parser)->m_startDoctypeDeclHandler)
#define endDoctypeDeclHandler (((Parser *)parser)->m_endDoctypeDeclHandler)
#define unparsedEntityDeclHandler (((Parser *)parser)->m_unparsedEntityDeclHandler)
#define notationDeclHandler (((Parser *)parser)->m_notationDeclHandler)
#define startNamespaceDeclHandler (((Parser *)parser)->m_startNamespaceDeclHandler)
@ -452,6 +456,8 @@ XML_Parser XML_ParserCreate(const XML_Char *encodingName)
startCdataSectionHandler = 0;
endCdataSectionHandler = 0;
defaultHandler = 0;
startDoctypeDeclHandler = 0;
endDoctypeDeclHandler = 0;
unparsedEntityDeclHandler = 0;
notationDeclHandler = 0;
startNamespaceDeclHandler = 0;
@ -765,6 +771,14 @@ void XML_SetDefaultHandlerExpand(XML_Parser parser,
defaultExpandInternalEntities = 1;
}
void XML_SetDoctypeDeclHandler(XML_Parser parser,
XML_StartDoctypeDeclHandler start,
XML_EndDoctypeDeclHandler end)
{
startDoctypeDeclHandler = start;
endDoctypeDeclHandler = end;
}
void XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
XML_UnparsedEntityDeclHandler handler)
{
@ -2200,6 +2214,15 @@ doProlog(XML_Parser parser,
enc = encoding;
}
break;
case XML_ROLE_DOCTYPE_NAME:
if (startDoctypeDeclHandler) {
const XML_Char *name = poolStoreString(&tempPool, enc, s, next);
if (!name)
return XML_ERROR_NO_MEMORY;
startDoctypeDeclHandler(handlerArg, name);
poolClear(&tempPool);
}
break;
#ifdef XML_DTD
case XML_ROLE_TEXT_DECL:
{
@ -2256,6 +2279,8 @@ doProlog(XML_Parser parser,
&& !notStandaloneHandler(handlerArg))
return XML_ERROR_NOT_STANDALONE;
}
if (endDoctypeDeclHandler)
endDoctypeDeclHandler(handlerArg);
break;
case XML_ROLE_INSTANCE_START:
processor = contentProcessor;

View file

@ -137,6 +137,15 @@ typedef void (*XML_DefaultHandler)(void *userData,
const XML_Char *s,
int len);
/* This is called for the start of the DOCTYPE declaration when the
name of the DOCTYPE is encountered. */
typedef void (*XML_StartDoctypeDeclHandler)(void *userData,
const XML_Char *doctypeName);
/* This is called for the start of the DOCTYPE declaration when the
closing > is encountered, but after processing any external subset. */
typedef void (*XML_EndDoctypeDeclHandler)(void *userData);
/* This is called for a declaration of an unparsed (NDATA)
entity. The base argument is whatever was set by XML_SetBase.
The entityName, systemId and notationName arguments will never be null.
@ -308,6 +317,11 @@ void XMLPARSEAPI
XML_SetDefaultHandlerExpand(XML_Parser parser,
XML_DefaultHandler handler);
void XMLPARSEAPI
XML_SetDoctypeDeclHandler(XML_Parser parser,
XML_StartDoctypeDeclHandler start,
XML_EndDoctypeDeclHandler end);
void XMLPARSEAPI
XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
XML_UnparsedEntityDeclHandler handler);

View file

@ -412,13 +412,31 @@ void metaCharacterData(XML_Parser parser, const XML_Char *s, int len)
fputts(T("/>\n"), fp);
}
static
void metaStartDoctypeDecl(XML_Parser parser, const XML_Char *doctypeName)
{
FILE *fp = XML_GetUserData(parser);
ftprintf(fp, T("<startdoctype name=\"%s\""), doctypeName);
metaLocation(parser);
fputts(T("/>\n"), fp);
}
static
void metaEndDoctypeDecl(XML_Parser parser)
{
FILE *fp = XML_GetUserData(parser);
fputts(T("<enddoctype"), fp);
metaLocation(parser);
fputts(T("/>\n"), fp);
}
static
void metaUnparsedEntityDecl(XML_Parser parser,
const XML_Char *entityName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId,
const XML_Char *notationName)
const XML_Char *entityName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId,
const XML_Char *notationName)
{
FILE *fp = XML_GetUserData(parser);
ftprintf(fp, T("<entity name=\"%s\""), entityName);
@ -687,6 +705,7 @@ int tmain(int argc, XML_Char **argv)
XML_SetCommentHandler(parser, metaComment);
XML_SetCdataSectionHandler(parser, metaStartCdataSection, metaEndCdataSection);
XML_SetCharacterDataHandler(parser, metaCharacterData);
XML_SetDoctypeDeclHandler(parser, metaStartDoctypeDecl, metaEndDoctypeDecl);
XML_SetUnparsedEntityDeclHandler(parser, metaUnparsedEntityDecl);
XML_SetNotationDeclHandler(parser, metaNotationDecl);
XML_SetNamespaceDeclHandler(parser, metaStartNamespaceDecl, metaEndNamespaceDecl);