]> code.delx.au - gnu-emacs/blobdiff - src/xml.c
Merge from trunk.
[gnu-emacs] / src / xml.c
index 63041c96b24ff524332a3eb846d3c43c95a479ae..0b39f3e603150953336c1014ef7329be20ebdc4b 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -71,6 +71,14 @@ make_dom (xmlNode *node)
       else
        return Qnil;
     }
+  else if (node->type == XML_COMMENT_NODE)
+    {
+      if (node->content)
+       return list3 (intern ("comment"), Qnil,
+                     build_string ((char *) node->content));
+      else
+       return Qnil;
+    }
   else
     return Qnil;
 }
@@ -79,11 +87,10 @@ static Lisp_Object
 parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int htmlp)
 {
   xmlDoc *doc;
-  xmlNode *node;
   Lisp_Object result = Qnil;
   const char *burl = "";
-  EMACS_INT bytes;
-  EMACS_INT istart, iend;
+  ptrdiff_t bytes;
+  ptrdiff_t istart, iend;
 
   LIBXML_TEST_VERSION;
 
@@ -117,11 +124,29 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
 
   if (doc != NULL)
     {
-      node = xmlDocGetRootElement (doc);
-      if (node != NULL)
-       result = make_dom (node);
+      /* If the document is just comments, then this should get us the
+        nodes anyway. */
+      xmlNode *n = doc->children->next;
+      Lisp_Object r = Qnil;
+
+      while (n) {
+       if (!NILP (r))
+         result = Fcons (r, result);
+       r = make_dom (n);
+       n = n->next;
+      }
+
+      if (NILP (result)) {
+       /* The document isn't just comments, so get the tree the
+          proper way. */
+       xmlNode *node = xmlDocGetRootElement (doc);
+       if (node != NULL)
+         result = make_dom (node);
+      } else
+       result = Fcons (intern ("top"),
+                       Fcons (Qnil, Fnreverse (Fcons (r, result))));
+
       xmlFreeDoc (doc);
-      xmlCleanupParser ();
     }
 
   return result;