Mercurial > emacs
comparison src/xml.c @ 110472:52590453d4f9
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.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Tue, 21 Sep 2010 23:10:16 -0400 |
parents | a828354ee483 |
children | 49d445615c07 |
comparison
equal
deleted
inserted
replaced
110471:6afc6a92ca9b | 110472:52590453d4f9 |
---|---|
28 #include "lisp.h" | 28 #include "lisp.h" |
29 #include "buffer.h" | 29 #include "buffer.h" |
30 | 30 |
31 Lisp_Object make_dom (xmlNode *node) | 31 Lisp_Object make_dom (xmlNode *node) |
32 { | 32 { |
33 if (node->type == XML_ELEMENT_NODE) { | 33 if (node->type == XML_ELEMENT_NODE) |
34 Lisp_Object result = Fcons (intern (node->name), Qnil); | 34 { |
35 xmlNode *child; | 35 Lisp_Object result = Fcons (intern (node->name), Qnil); |
36 xmlAttr *property; | 36 xmlNode *child; |
37 xmlAttr *property; | |
38 Lisp_Object plist = Qnil; | |
37 | 39 |
38 /* First add the attributes. */ | 40 /* First add the attributes. */ |
39 property = node->properties; | 41 property = node->properties; |
40 while (property != NULL) { | 42 while (property != NULL) |
41 if (property->children && | 43 { |
42 property->children->content) { | 44 if (property->children && |
43 char *pname = xmalloc (strlen (property->name) + 2); | 45 property->children->content) |
44 *pname = ':'; | 46 { |
45 strcpy(pname + 1, property->name); | 47 plist = Fcons (Fcons (intern (property->name), |
46 result = Fcons (Fcons (intern (pname), | 48 build_string (property->children->content)), |
47 build_string(property->children->content)), | 49 plist); |
48 result); | 50 } |
49 xfree (pname); | 51 property = property->next; |
50 } | 52 } |
51 property = property->next; | 53 result = Fcons (Fnreverse (plist), result); |
54 | |
55 /* Then add the children of the node. */ | |
56 child = node->children; | |
57 while (child != NULL) | |
58 { | |
59 result = Fcons (make_dom (child), result); | |
60 child = child->next; | |
61 } | |
62 | |
63 return Fnreverse (result); | |
52 } | 64 } |
53 /* Then add the children of the node. */ | 65 else if (node->type == XML_TEXT_NODE) |
54 child = node->children; | 66 { |
55 while (child != NULL) { | 67 if (node->content) |
56 result = Fcons (make_dom (child), result); | 68 return build_string (node->content); |
57 child = child->next; | 69 else |
70 return Qnil; | |
58 } | 71 } |
59 return Fnreverse (result); | 72 else |
60 } else if (node->type == XML_TEXT_NODE) { | |
61 Lisp_Object content = Qnil; | |
62 | |
63 if (node->content) | |
64 content = build_string (node->content); | |
65 | |
66 return Fcons (intern (node->name), content); | |
67 } else | |
68 return Qnil; | 73 return Qnil; |
69 } | 74 } |
70 | 75 |
71 static Lisp_Object | 76 static Lisp_Object |
72 parse_string (Lisp_Object string, Lisp_Object base_url, int htmlp) | 77 parse_string (Lisp_Object string, Lisp_Object base_url, int htmlp) |
79 | 84 |
80 LIBXML_TEST_VERSION; | 85 LIBXML_TEST_VERSION; |
81 | 86 |
82 CHECK_STRING (string); | 87 CHECK_STRING (string); |
83 | 88 |
84 if (! NILP (base_url)) { | 89 if (! NILP (base_url)) |
85 CHECK_STRING (base_url); | 90 { |
86 burl = SDATA (base_url); | 91 CHECK_STRING (base_url); |
87 } | 92 burl = SDATA (base_url); |
93 } | |
88 | 94 |
89 if (htmlp) | 95 doc = htmlp |
90 doc = htmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", | 96 ? htmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", |
91 HTML_PARSE_RECOVER|HTML_PARSE_NONET| | 97 HTML_PARSE_RECOVER|HTML_PARSE_NONET| |
92 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR); | 98 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR) |
93 else | 99 : xmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", |
94 doc = xmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", | 100 XML_PARSE_NONET|XML_PARSE_NOWARNING| |
95 XML_PARSE_NONET|XML_PARSE_NOWARNING| | 101 XML_PARSE_NOERROR); |
96 XML_PARSE_NOERROR); | |
97 | 102 |
98 if (doc != NULL) { | 103 if (doc != NULL) |
99 node = xmlDocGetRootElement (doc); | 104 { |
100 if (node != NULL) | 105 node = xmlDocGetRootElement (doc); |
101 result = make_dom (node); | 106 if (node != NULL) |
102 | 107 result = make_dom (node); |
103 xmlFreeDoc (doc); | 108 xmlFreeDoc (doc); |
104 xmlCleanupParser (); | 109 xmlCleanupParser (); |
105 } | 110 } |
106 | 111 |
107 return result; | 112 return result; |
108 } | 113 } |
109 | 114 |
110 DEFUN ("html-parse-string", Fhtml_parse_string, Shtml_parse_string, | 115 DEFUN ("xml-parse-html-string-internal", Fxml_parse_html_string_internal, |
116 Sxml_parse_html_string_internal, | |
111 1, 2, 0, | 117 1, 2, 0, |
112 doc: /* Parse STRING as an HTML document and return the parse tree. | 118 doc: /* Parse STRING as an HTML document and return the parse tree. |
113 If BASE-URL is non-nil, it will be used to expand relative URLs in | 119 If BASE-URL is non-nil, it is used to expand relative URLs. */) |
114 the HTML document. */) | |
115 (Lisp_Object string, Lisp_Object base_url) | 120 (Lisp_Object string, Lisp_Object base_url) |
116 { | 121 { |
117 return parse_string (string, base_url, 1); | 122 return parse_string (string, base_url, 1); |
118 } | 123 } |
119 | 124 |
120 DEFUN ("xml-parse-string", Fxml_parse_string, Sxml_parse_string, | 125 DEFUN ("xml-parse-string-internal", Fxml_parse_string_internal, |
126 Sxml_parse_string_internal, | |
121 1, 2, 0, | 127 1, 2, 0, |
122 doc: /* Parse STRING as an XML document and return the parse tree. | 128 doc: /* Parse STRING as an XML document and return the parse tree. |
123 If BASE-URL is non-nil, it will be used to expand relative URLs in | 129 If BASE-URL is non-nil, it is used to expand relative URLs. */) |
124 the XML document. */) | |
125 (Lisp_Object string, Lisp_Object base_url) | 130 (Lisp_Object string, Lisp_Object base_url) |
126 { | 131 { |
127 return parse_string (string, base_url, 0); | 132 return parse_string (string, base_url, 0); |
128 } | 133 } |
129 | 134 |
132 Initialization | 137 Initialization |
133 ***********************************************************************/ | 138 ***********************************************************************/ |
134 void | 139 void |
135 syms_of_xml (void) | 140 syms_of_xml (void) |
136 { | 141 { |
137 defsubr (&Shtml_parse_string); | 142 defsubr (&Sxml_parse_html_string_internal); |
138 defsubr (&Sxml_parse_string); | 143 defsubr (&Sxml_parse_string_internal); |
139 } | 144 } |
140 | 145 |
141 #endif /* HAVE_LIBXML2 */ | 146 #endif /* HAVE_LIBXML2 */ |