diff options
| author | Chong Yidong | 2010-09-21 23:10:16 -0400 |
|---|---|---|
| committer | Chong Yidong | 2010-09-21 23:10:16 -0400 |
| commit | 4b9832a6f2031a95f72e06040c8860dca49bd2dd (patch) | |
| tree | c7be90e44ea819dbc847754df19f71b423224c57 /src/xml.c | |
| parent | 1114abdb3d5a0f4f86d7a28f8c523c6f07790208 (diff) | |
| download | emacs-4b9832a6f2031a95f72e06040c8860dca49bd2dd.tar.gz emacs-4b9832a6f2031a95f72e06040c8860dca49bd2dd.zip | |
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
| @@ -30,41 +30,46 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 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 | 37 | xmlAttr *property; | |
| 38 | /* First add the attributes. */ | 38 | Lisp_Object plist = Qnil; |
| 39 | property = node->properties; | 39 | |
| 40 | while (property != NULL) { | 40 | /* First add the attributes. */ |
| 41 | if (property->children && | 41 | property = node->properties; |
| 42 | property->children->content) { | 42 | while (property != NULL) |
| 43 | char *pname = xmalloc (strlen (property->name) + 2); | 43 | { |
| 44 | *pname = ':'; | 44 | if (property->children && |
| 45 | strcpy(pname + 1, property->name); | 45 | property->children->content) |
| 46 | result = Fcons (Fcons (intern (pname), | 46 | { |
| 47 | build_string(property->children->content)), | 47 | plist = Fcons (Fcons (intern (property->name), |
| 48 | result); | 48 | build_string (property->children->content)), |
| 49 | xfree (pname); | 49 | plist); |
| 50 | } | 50 | } |
| 51 | property = property->next; | 51 | property = property->next; |
| 52 | } | ||
| 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 | ||
| @@ -81,47 +86,47 @@ parse_string (Lisp_Object string, Lisp_Object base_url, int htmlp) | |||
| 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); |
| 88 | 93 | } | |
| 89 | if (htmlp) | ||
| 90 | doc = htmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", | ||
| 91 | HTML_PARSE_RECOVER|HTML_PARSE_NONET| | ||
| 92 | HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR); | ||
| 93 | else | ||
| 94 | doc = xmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", | ||
| 95 | XML_PARSE_NONET|XML_PARSE_NOWARNING| | ||
| 96 | XML_PARSE_NOERROR); | ||
| 97 | |||
| 98 | if (doc != NULL) { | ||
| 99 | node = xmlDocGetRootElement (doc); | ||
| 100 | if (node != NULL) | ||
| 101 | result = make_dom (node); | ||
| 102 | 94 | ||
| 103 | xmlFreeDoc (doc); | 95 | doc = htmlp |
| 104 | xmlCleanupParser (); | 96 | ? htmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", |
| 105 | } | 97 | HTML_PARSE_RECOVER|HTML_PARSE_NONET| |
| 98 | HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR) | ||
| 99 | : xmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", | ||
| 100 | XML_PARSE_NONET|XML_PARSE_NOWARNING| | ||
| 101 | XML_PARSE_NOERROR); | ||
| 102 | |||
| 103 | if (doc != NULL) | ||
| 104 | { | ||
| 105 | node = xmlDocGetRootElement (doc); | ||
| 106 | if (node != NULL) | ||
| 107 | result = make_dom (node); | ||
| 108 | xmlFreeDoc (doc); | ||
| 109 | xmlCleanupParser (); | ||
| 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); |
| @@ -134,8 +139,8 @@ the XML document. */) | |||
| 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 */ |