From 9a33766c6217f3beb247bead75b41258b97e78a0 Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Wed, 4 Oct 2006 10:47:19 +0100 Subject: [PATCH] Further to the previous fix, don't clear the content buffer afetr an open/close tag callback -- clear it before. This stops included content from being lost. --- src/libCStreamedXML/parser.c | 13 ++++++------- src/libStreamedXML/Parser.cpp | 12 ++++++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/libCStreamedXML/parser.c b/src/libCStreamedXML/parser.c index d0332eb..cffb56a 100644 --- a/src/libCStreamedXML/parser.c +++ b/src/libCStreamedXML/parser.c @@ -110,7 +110,7 @@ int csxml_feedChar(struct csxml* ctx, char ch) int try; #ifdef DEBUG_STATE_MACHINE - printf("Character '%c' (%02X), state %d\n", ch, ch, ctx->state); + printf("%p: Character '%c' (%02X), state %d, buffer %s\n", ctx, ch, ch, ctx->state, ctx->buffer.data); #endif #define ERROR(_reason) do { \ @@ -398,11 +398,11 @@ int csxml_feedChar(struct csxml* ctx, char ch) default: switch(ch) { case L'>': + CLEAR_BUFFER(buffer); TRY(list_push(ctx, &ctx->elemStack, &ctx->elemName)); ctx->state = StateNone; TRY(ctx->element(ctx, ctx->elemName.data, 0)); ++ctx->elementDepth; - CLEAR_BUFFER(buffer); break; case L'/': @@ -489,9 +489,9 @@ int csxml_feedChar(struct csxml* ctx, char ch) ctx->state = StateNeedClose; } else if(ch == '>') { ctx->state = StateNone; + CLEAR_BUFFER(buffer); TRY(ctx->element(ctx, ctx->elemName.data, ctx->elemAttrVals.len)); TRY(list_push(ctx, &ctx->elemStack, &ctx->elemName)); - CLEAR_BUFFER(buffer); ++ctx->elementDepth; } else ERROR("Invalid character after attribute."); break; @@ -501,9 +501,9 @@ int csxml_feedChar(struct csxml* ctx, char ch) case StateNeedClose: if(ch != '>') ERROR("Stray `/' in open tag."); ctx->state = StateNone; + CLEAR_BUFFER(buffer); TRY(ctx->element(ctx, ctx->elemName.data, ctx->elemAttrVals.len)); TRY(ctx->closeTag(ctx, ctx->elemName.data)); - CLEAR_BUFFER(buffer); break; case StateClose: @@ -528,10 +528,9 @@ int csxml_feedChar(struct csxml* ctx, char ch) TRY(buffer_copy(ctx, &ctx->elemName, list_pop(&ctx->elemStack))); if(strcmp(ctx->elemName.data, ctx->buffer.data)) ERROR("Mismatched close tag."); ctx->state = StateNone; + CLEAR_BUFFER(buffer); TRY(ctx->closeTag(ctx, ctx->elemName.data)); --ctx->elementDepth; - CLEAR_BUFFER(buffer); - } break; @@ -541,9 +540,9 @@ int csxml_feedChar(struct csxml* ctx, char ch) TRY(buffer_copy(ctx, &ctx->elemName, list_pop(&ctx->elemStack))); if(strcmp(ctx->elemName.data, ctx->buffer.data)) ERROR("Mismatched close tag."); ctx->state = StateNone; + CLEAR_BUFFER(buffer); TRY(ctx->closeTag(ctx, ctx->elemName.data)); --ctx->elementDepth; - CLEAR_BUFFER(buffer); break; case StateEntity: diff --git a/src/libStreamedXML/Parser.cpp b/src/libStreamedXML/Parser.cpp index 3dcc9a9..ee6f0f6 100644 --- a/src/libStreamedXML/Parser.cpp +++ b/src/libStreamedXML/Parser.cpp @@ -383,9 +383,9 @@ doBuffer: case L'>': elemStack.push_back(buffer); state = StateNone; + buffer.clear(); callback->element(buffer, elemAttrs); ++elementDepth; - buffer.clear(); break; case L'/': @@ -413,8 +413,8 @@ doBuffer: case L'>': elemStack.push_back(elemName); state = StateNone; - callback->element(elemName, elemAttrs); buffer.clear(); + callback->element(elemName, elemAttrs); ++elementDepth; break; @@ -475,9 +475,9 @@ doBuffer: state = StateNeedClose; } else if(ch == L'>') { state = StateNone; + buffer.clear(); callback->element(elemName, elemAttrs); elemStack.push_back(elemName); - buffer.clear(); ++elementDepth; } else ERROR(L"Invalid character after attribute."); break; @@ -487,9 +487,9 @@ doBuffer: case StateNeedClose: if(ch != L'>') ERROR(L"Stray `/' in open tag."); state = StateNone; + buffer.clear(); callback->element(elemName, elemAttrs); callback->closeTag(elemName); - buffer.clear(); break; case StateClose: @@ -514,8 +514,8 @@ doBuffer: if(elemStack.back() != buffer) ERROR(L"Mismatched close tag."); elemStack.pop_back(); state = StateNone; - callback->closeTag(buffer); buffer.clear(); + callback->closeTag(buffer); --elementDepth; } break; @@ -526,8 +526,8 @@ doBuffer: if(elemStack.back() != elemName) ERROR(L"Mismatched close tag."); elemStack.pop_back(); state = StateNone; - callback->closeTag(elemName); buffer.clear(); + callback->closeTag(elemName); --elementDepth; break;