diff options
Diffstat (limited to 'src/xml.c')
| -rw-r--r-- | src/xml.c | 37 |
1 files changed, 31 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Interface to libxml2. | 1 | /* Interface to libxml2. |
| 2 | Copyright (C) 2010-2011 Free Software Foundation, Inc. | 2 | Copyright (C) 2010-2012 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This file is part of GNU Emacs. | 4 | This file is part of GNU Emacs. |
| 5 | 5 | ||
| @@ -71,6 +71,14 @@ make_dom (xmlNode *node) | |||
| 71 | else | 71 | else |
| 72 | return Qnil; | 72 | return Qnil; |
| 73 | } | 73 | } |
| 74 | else if (node->type == XML_COMMENT_NODE) | ||
| 75 | { | ||
| 76 | if (node->content) | ||
| 77 | return list3 (intern ("comment"), Qnil, | ||
| 78 | build_string ((char *) node->content)); | ||
| 79 | else | ||
| 80 | return Qnil; | ||
| 81 | } | ||
| 74 | else | 82 | else |
| 75 | return Qnil; | 83 | return Qnil; |
| 76 | } | 84 | } |
| @@ -79,7 +87,6 @@ static Lisp_Object | |||
| 79 | parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int htmlp) | 87 | parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int htmlp) |
| 80 | { | 88 | { |
| 81 | xmlDoc *doc; | 89 | xmlDoc *doc; |
| 82 | xmlNode *node; | ||
| 83 | Lisp_Object result = Qnil; | 90 | Lisp_Object result = Qnil; |
| 84 | const char *burl = ""; | 91 | const char *burl = ""; |
| 85 | EMACS_INT bytes; | 92 | EMACS_INT bytes; |
| @@ -117,11 +124,29 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html | |||
| 117 | 124 | ||
| 118 | if (doc != NULL) | 125 | if (doc != NULL) |
| 119 | { | 126 | { |
| 120 | node = xmlDocGetRootElement (doc); | 127 | /* If the document is just comments, then this should get us the |
| 121 | if (node != NULL) | 128 | nodes anyway. */ |
| 122 | result = make_dom (node); | 129 | xmlNode *n = doc->children->next; |
| 130 | Lisp_Object r = Qnil; | ||
| 131 | |||
| 132 | while (n) { | ||
| 133 | if (!NILP (r)) | ||
| 134 | result = Fcons (r, result); | ||
| 135 | r = make_dom (n); | ||
| 136 | n = n->next; | ||
| 137 | } | ||
| 138 | |||
| 139 | if (NILP (result)) { | ||
| 140 | /* The document isn't just comments, so get the tree the | ||
| 141 | proper way. */ | ||
| 142 | xmlNode *node = xmlDocGetRootElement (doc); | ||
| 143 | if (node != NULL) | ||
| 144 | result = make_dom (node); | ||
| 145 | } else | ||
| 146 | result = Fcons (intern ("top"), | ||
| 147 | Fcons (Qnil, Fnreverse (Fcons (r, result)))); | ||
| 148 | |||
| 123 | xmlFreeDoc (doc); | 149 | xmlFreeDoc (doc); |
| 124 | xmlCleanupParser (); | ||
| 125 | } | 150 | } |
| 126 | 151 | ||
| 127 | return result; | 152 | return result; |