From bacb3a4e239abf188bbd772c1d1013b6812d1fd9 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Thu, 30 Mar 2023 00:00:55 -0700 Subject: [PATCH] xml: miscellaneous cleanups --- include/wimlib/xmlproc.h | 5 +---- src/xml.c | 7 +++---- src/xmlproc.c | 16 +++++++--------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/include/wimlib/xmlproc.h b/include/wimlib/xmlproc.h index 374d27e2..c82ce57f 100644 --- a/include/wimlib/xmlproc.h +++ b/include/wimlib/xmlproc.h @@ -38,9 +38,6 @@ struct xml_node * xml_new_element_with_text(struct xml_node *parent, const tchar *name, const tchar *text); -struct xml_node * -xml_new_attrib(struct xml_node *parent, const tchar *name, const tchar *value); - void xml_add_child(struct xml_node *parent, struct xml_node *child); @@ -77,7 +74,7 @@ xml_legal_value(const tchar *value); /*****************************************************************************/ int -xml_parse_document(const tchar *p, struct xml_node **doc_ret); +xml_parse_document(const tchar *raw_doc, struct xml_node **doc_ret); /*****************************************************************************/ diff --git a/src/xml.c b/src/xml.c index 3194978b..63c3b4fb 100644 --- a/src/xml.c +++ b/src/xml.c @@ -291,7 +291,8 @@ xml_get_text_by_path(struct xml_node *root, const tchar *path) * or empty) an element containing text. */ static int -xml_set_text_by_path(struct xml_node *root, const tchar *path, const tchar *text) +xml_set_text_by_path(struct xml_node *root, const tchar *path, + const tchar *text) { int ret; struct xml_node *element; @@ -304,9 +305,7 @@ xml_set_text_by_path(struct xml_node *root, const tchar *path, const tchar *text return xml_element_set_text(element, text); } else { /* Remove */ - element = xml_get_element_by_path(root, path); - if (element) - xml_free_node(element); + xml_free_node(xml_get_element_by_path(root, path)); return 0; } } diff --git a/src/xmlproc.c b/src/xmlproc.c index 529fd690..48569ff8 100644 --- a/src/xmlproc.c +++ b/src/xmlproc.c @@ -592,8 +592,6 @@ parse_element(const tchar **pp, struct xml_node *parent, int depth, if (*p == '/') { /* Closing an empty element tag */ p++; - CHECK(*p == '>'); - p++; } else { /* Closing the start tag */ CHECK(*p == '>'); @@ -609,9 +607,9 @@ parse_element(const tchar **pp, struct xml_node *parent, int depth, CHECK(!tstrncmp(p, name_start, name_len)); p += name_len; skip_whitespace(&p); - CHECK(*p == '>'); - p++; } + CHECK(*p == '>'); + p++; *pp = p; if (element_ret) *element_ret = element; @@ -695,14 +693,14 @@ xml_escape_and_puts(struct xml_out_buf *buf, const tchar *str) } static void -xml_write_element(struct xml_node *node, struct xml_out_buf *buf) +xml_write_element(struct xml_node *element, struct xml_out_buf *buf) { struct xml_node *child; /* Write the start tag. */ xml_puts(buf, T("<")); - xml_puts(buf, node->name); - xml_node_for_each_child(node, child) { + xml_puts(buf, element->name); + xml_node_for_each_child(element, child) { if (child->type == XML_ATTRIBUTE_NODE) { xml_puts(buf, T(" ")); xml_puts(buf, child->name); @@ -714,7 +712,7 @@ xml_write_element(struct xml_node *node, struct xml_out_buf *buf) xml_puts(buf, T(">")); /* Write the contents. */ - xml_node_for_each_child(node, child) { + xml_node_for_each_child(element, child) { if (child->type == XML_TEXT_NODE) xml_escape_and_puts(buf, child->value); else if (child->type == XML_ELEMENT_NODE) @@ -723,7 +721,7 @@ xml_write_element(struct xml_node *node, struct xml_out_buf *buf) /* Write the end tag. */ xml_puts(buf, T("name); + xml_puts(buf, element->name); xml_puts(buf, T(">")); } -- 2.43.0