From b12f3033ac773b6b22d558bd8f4c7b3de53f2867 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Thu, 24 Apr 2008 09:17:15 +0200 Subject: [PATCH] XML: Implemented xml_skip_element(). --- sherlock/xml/parse.c | 22 ++++++++++++++++++++++ sherlock/xml/xml.h | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/sherlock/xml/parse.c b/sherlock/xml/parse.c index 67ef1076..f771b304 100644 --- a/sherlock/xml/parse.c +++ b/sherlock/xml/parse.c @@ -1137,6 +1137,28 @@ epilog: ASSERT(0); } +uns +xml_next_state(struct xml_context *ctx, uns pull) +{ + uns saved = ctx->pull; + ctx->pull = pull; + uns res = xml_next(ctx); + ctx->pull = saved; + return res; +} + +uns +xml_skip_element(struct xml_context *ctx) +{ + ASSERT(ctx->state == XML_STATE_STAG); + struct xml_node *node = ctx->node; + uns saved = ctx->pull, res; + ctx->pull = XML_PULL_ETAG; + while ((res = xml_next(ctx)) && ctx->node != node); + ctx->pull = saved; + return res; +} + uns xml_parse(struct xml_context *ctx) { diff --git a/sherlock/xml/xml.h b/sherlock/xml/xml.h index 01b115da..08a4d6f6 100644 --- a/sherlock/xml/xml.h +++ b/sherlock/xml/xml.h @@ -232,6 +232,12 @@ uns xml_parse(struct xml_context *ctx); /* Parse with the PUSH interface, return XML_STATE_x (zero on EOF or fatal error) */ uns xml_next(struct xml_context *ctx); +/* Equivalent to xml_next, but with temporarily changed ctx->pull value */ +uns xml_next_state(struct xml_context *ctx, uns pull); + +/* May be called on XML_STATE_STAG to skip it's content; can return XML_STATE_ETAG or XML_STATE_EOF on fatal error */ +uns xml_skip_element(struct xml_context *ctx); + /* Returns the current row number in the document entity */ uns xml_row(struct xml_context *ctx); -- 2.39.2