XML_CharacterDataHandler characterDataHandler;
XML_ProcessingInstructionHandler processingInstructionHandler;
XML_CommentHandler commentHandler;
+ XML_StartCdataSectionHandler startCdataSectionHandler;
+ XML_EndCdataSectionHandler endCdataSectionHandler;
XML_DefaultHandler defaultHandler;
XML_UnparsedEntityDeclHandler unparsedEntityDeclHandler;
XML_NotationDeclHandler notationDeclHandler;
#define characterDataHandler (((Parser *)parser)->characterDataHandler)
#define processingInstructionHandler (((Parser *)parser)->processingInstructionHandler)
#define commentHandler (((Parser *)parser)->commentHandler)
+#define startCdataSectionHandler (((Parser *)parser)->startCdataSectionHandler)
+#define endCdataSectionHandler (((Parser *)parser)->endCdataSectionHandler)
#define defaultHandler (((Parser *)parser)->defaultHandler)
#define unparsedEntityDeclHandler (((Parser *)parser)->unparsedEntityDeclHandler)
#define notationDeclHandler (((Parser *)parser)->notationDeclHandler)
characterDataHandler = 0;
processingInstructionHandler = 0;
commentHandler = 0;
+ startCdataSectionHandler = 0;
+ endCdataSectionHandler = 0;
defaultHandler = 0;
unparsedEntityDeclHandler = 0;
notationDeclHandler = 0;
XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler;
XML_ProcessingInstructionHandler oldProcessingInstructionHandler = processingInstructionHandler;
XML_CommentHandler oldCommentHandler = commentHandler;
+ XML_StartCdataSectionHandler oldStartCdataSectionHandler = startCdataSectionHandler;
+ XML_EndCdataSectionHandler oldEndCdataSectionHandler = endCdataSectionHandler;
XML_DefaultHandler oldDefaultHandler = defaultHandler;
XML_ExternalEntityRefHandler oldExternalEntityRefHandler = externalEntityRefHandler;
XML_UnknownEncodingHandler oldUnknownEncodingHandler = unknownEncodingHandler;
characterDataHandler = oldCharacterDataHandler;
processingInstructionHandler = oldProcessingInstructionHandler;
commentHandler = oldCommentHandler;
+ startCdataSectionHandler = oldStartCdataSectionHandler;
+ endCdataSectionHandler = oldEndCdataSectionHandler;
defaultHandler = oldDefaultHandler;
externalEntityRefHandler = oldExternalEntityRefHandler;
unknownEncodingHandler = oldUnknownEncodingHandler;
commentHandler = handler;
}
+void XML_SetCdataSectionHandler(XML_Parser parser,
+ XML_StartCdataSectionHandler start,
+ XML_EndCdataSectionHandler end)
+{
+ startCdataSectionHandler = start;
+ endCdataSectionHandler = end;
+}
+
void XML_SetDefaultHandler(XML_Parser parser,
XML_DefaultHandler handler)
{
case XML_TOK_CDATA_SECT_OPEN:
{
enum XML_Error result;
- if (characterDataHandler)
+ if (startCdataSectionHandler)
+ startCdataSectionHandler(handlerArg);
+#if 0
+ /* Suppose you doing a transformation on a document that involves
+ changing only the character data. You set up a defaultHandler
+ and a characterDataHandler. The defaultHandler simply copies
+ characters through. The characterDataHandler does the transformation
+ and writes the characters out escaping them as necessary. This case
+ will fail to work if we leave out the following two lines (because &
+ and < inside CDATA sections will be incorrectly escaped).
+
+ However, now we have a start/endCdataSectionHandler, so it seems
+ easier to let the user deal with this. */
+
+ else if (characterDataHandler)
characterDataHandler(handlerArg, dataBuf, 0);
+#endif
else if (defaultHandler)
reportDefault(parser, enc, s, next);
result = doCdataSection(parser, enc, &next, end, nextPtr);
*eventEndPP = next;
switch (tok) {
case XML_TOK_CDATA_SECT_CLOSE:
- if (characterDataHandler)
+ if (endCdataSectionHandler)
+ endCdataSectionHandler(handlerArg);
+#if 0
+ /* see comment under XML_TOK_CDATA_SECT_OPEN */
+ else if (characterDataHandler)
characterDataHandler(handlerArg, dataBuf, 0);
+#endif
else if (defaultHandler)
reportDefault(parser, enc, s, next);
*startPtr = next;
/* data is 0 terminated */
typedef void (*XML_CommentHandler)(void *userData, const XML_Char *data);
+typedef void (*XML_StartCdataSectionHandler)(void *userData);
+typedef void (*XML_EndCdataSectionHandler)(void *userData);
+
/* This is called for any characters in the XML document for
which there is no applicable handler. This includes both
characters that are part of markup which is of a kind that is
XML_SetCommentHandler(XML_Parser parser,
XML_CommentHandler handler);
+void XMLPARSEAPI
+XML_SetCdataSectionHandler(XML_Parser parser,
+ XML_StartCdataSectionHandler start,
+ XML_EndCdataSectionHandler end);
+
/* This sets the default handler and also inhibits expansion of internal entities.
The entity reference will be passed to the default handler. */
fputts(T("/>\n"), fp);
}
+static
+void metaStartCdataSection(XML_Parser parser)
+{
+ FILE *fp = XML_GetUserData(parser);
+ fputts(T("<startcdata"), fp);
+ metaLocation(parser);
+ fputts(T("/>\n"), fp);
+}
+
+static
+void metaEndCdataSection(XML_Parser parser)
+{
+ FILE *fp = XML_GetUserData(parser);
+ fputts(T("<endcdata"), fp);
+ metaLocation(parser);
+ fputts(T("/>\n"), fp);
+}
+
static
void metaCharacterData(XML_Parser parser, const XML_Char *s, int len)
{
XML_SetElementHandler(parser, metaStartElement, metaEndElement);
XML_SetProcessingInstructionHandler(parser, metaProcessingInstruction);
XML_SetCommentHandler(parser, metaComment);
+ XML_SetCdataSectionHandler(parser, metaStartCdataSection, metaEndCdataSection);
XML_SetCharacterDataHandler(parser, metaCharacterData);
XML_SetUnparsedEntityDeclHandler(parser, metaUnparsedEntityDecl);
XML_SetNotationDeclHandler(parser, metaNotationDecl);