]> wimlib.net Git - wimlib/commitdiff
xml: miscellaneous cleanups
authorEric Biggers <ebiggers3@gmail.com>
Thu, 30 Mar 2023 07:00:55 +0000 (00:00 -0700)
committerEric Biggers <ebiggers3@gmail.com>
Thu, 30 Mar 2023 07:00:55 +0000 (00:00 -0700)
include/wimlib/xmlproc.h
src/xml.c
src/xmlproc.c

index 374d27e2cc2c4667132964d655679e9f651a6688..c82ce57f3a2877eb9d0d8c8396c2eba5e9737026 100644 (file)
@@ -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);
 
 /*****************************************************************************/
 
index 3194978b015289df871daf5af8b828ae0dbe7d41..63c3b4fb03e444a36386218e6671ff79ec723556 100644 (file)
--- 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;
        }
 }
index 529fd6909152e0747c168240f743d40a5f2c1bce..48569ff87f9fbc7461c63762596bc90d7236a8a3 100644 (file)
@@ -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("</"));
-       xml_puts(buf, node->name);
+       xml_puts(buf, element->name);
        xml_puts(buf, T(">"));
 }