]> code.delx.au - gnu-emacs/blobdiff - src/xml.c
Merge from trunk.
[gnu-emacs] / src / xml.c
index a8a4d8122da32f90ee1646392b85808a7c3f2d13..0b39f3e603150953336c1014ef7329be20ebdc4b 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -87,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;
 
@@ -125,24 +124,29 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
 
   if (doc != NULL)
     {
+      /* 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 (r != Qnil)
+       if (!NILP (r))
          result = Fcons (r, result);
        r = make_dom (n);
        n = n->next;
       }
 
-      if (result == Qnil)
-       result = r;
-      else
+      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;