summaryrefslogtreecommitdiff
path: root/src/xml.c
diff options
context:
space:
mode:
authorChong Yidong <cyd@stupidchicken.com>2010-09-21 23:10:16 -0400
committerChong Yidong <cyd@stupidchicken.com>2010-09-21 23:10:16 -0400
commit13881cc26218bab982706de847cb6ddcee8f3254 (patch)
tree819f3412bff66bbaac09c906e716801ba158e894 /src/xml.c
parent85937ea2be2f6b2fcf034fb338f8fe413a6447ab (diff)
downloademacs-13881cc26218bab982706de847cb6ddcee8f3254.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.c129
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 */