diff options
author | Chong Yidong <cyd@stupidchicken.com> | 2010-09-21 23:10:16 -0400 |
---|---|---|
committer | Chong Yidong <cyd@stupidchicken.com> | 2010-09-21 23:10:16 -0400 |
commit | 4b9832a6f2031a95f72e06040c8860dca49bd2dd (patch) | |
tree | c7be90e44ea819dbc847754df19f71b423224c57 /src/xml.c | |
parent | 1114abdb3d5a0f4f86d7a28f8c523c6f07790208 (diff) | |
download | emacs-4b9832a6f2031a95f72e06040c8860dca49bd2dd.tar.gz |
Rename libxml2 functions, and make parse tree format consistent with xml.el.
* xml.c: Switch to GNU indentation.
(make_dom): Change parse tree format to match xml.el.
(Fxml_parse_html_string_internal): Rename from html-parse-string.
(Fxml_parse_string_internal): Rename from xml-parse-string.
* configure.in: Announce whether libxml2 is linked to.
Diffstat (limited to 'src/xml.c')
-rw-r--r-- | src/xml.c | 129 |
1 files changed, 67 insertions, 62 deletions
diff --git a/src/xml.c b/src/xml.c index ddecabb5317..5829f1da538 100644 --- a/src/xml.c +++ b/src/xml.c @@ -30,41 +30,46 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ Lisp_Object make_dom (xmlNode *node) { - if (node->type == XML_ELEMENT_NODE) { - Lisp_Object result = Fcons (intern (node->name), Qnil); - xmlNode *child; - xmlAttr *property; - - /* First add the attributes. */ - property = node->properties; - while (property != NULL) { - if (property->children && - property->children->content) { - char *pname = xmalloc (strlen (property->name) + 2); - *pname = ':'; - strcpy(pname + 1, property->name); - result = Fcons (Fcons (intern (pname), - build_string(property->children->content)), - result); - xfree (pname); - } - property = property->next; + if (node->type == XML_ELEMENT_NODE) + { + Lisp_Object result = Fcons (intern (node->name), Qnil); + xmlNode *child; + xmlAttr *property; + Lisp_Object plist = Qnil; + + /* First add the attributes. */ + property = node->properties; + while (property != NULL) + { + if (property->children && + property->children->content) + { + plist = Fcons (Fcons (intern (property->name), + build_string (property->children->content)), + plist); + } + property = property->next; + } + result = Fcons (Fnreverse (plist), result); + + /* Then add the children of the node. */ + child = node->children; + while (child != NULL) + { + result = Fcons (make_dom (child), result); + child = child->next; + } + + return Fnreverse (result); } - /* Then add the children of the node. */ - child = node->children; - while (child != NULL) { - result = Fcons (make_dom (child), result); - child = child->next; + else if (node->type == XML_TEXT_NODE) + { + if (node->content) + return build_string (node->content); + else + return Qnil; } - return Fnreverse (result); - } else if (node->type == XML_TEXT_NODE) { - Lisp_Object content = Qnil; - - if (node->content) - content = build_string (node->content); - - return Fcons (intern (node->name), content); - } else + else return Qnil; } @@ -81,47 +86,47 @@ parse_string (Lisp_Object string, Lisp_Object base_url, int htmlp) CHECK_STRING (string); - if (! NILP (base_url)) { - CHECK_STRING (base_url); - burl = SDATA (base_url); - } - - if (htmlp) - doc = htmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", - HTML_PARSE_RECOVER|HTML_PARSE_NONET| - HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR); - else - doc = xmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", - XML_PARSE_NONET|XML_PARSE_NOWARNING| - XML_PARSE_NOERROR); - - if (doc != NULL) { - node = xmlDocGetRootElement (doc); - if (node != NULL) - result = make_dom (node); + if (! NILP (base_url)) + { + CHECK_STRING (base_url); + burl = SDATA (base_url); + } - xmlFreeDoc (doc); - xmlCleanupParser (); - } + doc = htmlp + ? htmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", + HTML_PARSE_RECOVER|HTML_PARSE_NONET| + HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR) + : xmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", + XML_PARSE_NONET|XML_PARSE_NOWARNING| + XML_PARSE_NOERROR); + + if (doc != NULL) + { + node = xmlDocGetRootElement (doc); + if (node != NULL) + result = make_dom (node); + xmlFreeDoc (doc); + xmlCleanupParser (); + } return result; } -DEFUN ("html-parse-string", Fhtml_parse_string, Shtml_parse_string, +DEFUN ("xml-parse-html-string-internal", Fxml_parse_html_string_internal, + Sxml_parse_html_string_internal, 1, 2, 0, doc: /* Parse STRING as an HTML document and return the parse tree. -If BASE-URL is non-nil, it will be used to expand relative URLs in -the HTML document. */) +If BASE-URL is non-nil, it is used to expand relative URLs. */) (Lisp_Object string, Lisp_Object base_url) { return parse_string (string, base_url, 1); } -DEFUN ("xml-parse-string", Fxml_parse_string, Sxml_parse_string, +DEFUN ("xml-parse-string-internal", Fxml_parse_string_internal, + Sxml_parse_string_internal, 1, 2, 0, doc: /* Parse STRING as an XML document and return the parse tree. -If BASE-URL is non-nil, it will be used to expand relative URLs in -the XML document. */) +If BASE-URL is non-nil, it is used to expand relative URLs. */) (Lisp_Object string, Lisp_Object base_url) { return parse_string (string, base_url, 0); @@ -134,8 +139,8 @@ the XML document. */) void syms_of_xml (void) { - defsubr (&Shtml_parse_string); - defsubr (&Sxml_parse_string); + defsubr (&Sxml_parse_html_string_internal); + defsubr (&Sxml_parse_string_internal); } #endif /* HAVE_LIBXML2 */ |