From b0639a0c6d2d5e1d35423fbed81781a393c63b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sowa?= Date: Thu, 10 Oct 2013 01:15:26 +0200 Subject: [PATCH] Support for self-closing tags. --- src/xml.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/xml.c b/src/xml.c index 08ac222..27550bc 100644 --- a/src/xml.c +++ b/src/xml.c @@ -535,6 +535,13 @@ static struct xml_node* xml_parse_node(struct xml_parser* parser) { goto exit_failure; } + /* If tag ends with `/' it's self closing, skip content lookup */ + if ('/' == tag_open->buffer[tag_open->length - 1]) { + /* Drop `/' + */ + --tag_open->length; + goto node_creation; + } /* If the content does not start with '<', a text content is assumed */ @@ -593,6 +600,7 @@ static struct xml_node* xml_parse_node(struct xml_parser* parser) { */ xml_string_free(tag_close); +node_creation:; struct xml_node* node = malloc(sizeof(struct xml_node)); node->name = tag_open; node->content = content;