all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Wojciech Meyer <wojciech.meyer@googlemail.com>
To: Chong Yidong <cyd@stupidchicken.com>
Cc: Leo <sdl.web@gmail.com>, emacs-devel@gnu.org
Subject: Re: Problems with xml-parse-string
Date: Thu, 23 Sep 2010 22:58:14 +0100	[thread overview]
Message-ID: <87hbhggm15.fsf@gmail.com> (raw)
In-Reply-To: <87vd5wo48a.fsf@stupidchicken.com> (Chong Yidong's message of "Thu, 23 Sep 2010 11:43:17 -0400")

[-- Attachment #1: Type: text/plain, Size: 1369 bytes --]

Chong Yidong <cyd@stupidchicken.com> writes:

> Leo <sdl.web@gmail.com> writes:
>
>> On 2010-09-23 00:59 +0100, Stefan Monnier wrote:
>>> FWIW, while I haven't use sml.el much, the little bit I've used it was
>>> not particularly pleasant, partly because of the odd format. I don't
>>> know how/why the xml.el was chosen and how much thought was put into
>>> it, but my experience with it is not 100% positive.
>>
>> That looks like my experience too.
>
> The main differences in the "new" format are (i) listing attributes as
> (:foo bar) inside the element list, rather than in an alist after the
> element name, (ii) listing text as (text "foo") rather than "foo", and
> (iii) the as-yet-unresolved issue with XML namespaces, which probably
> needs to be fixed in xml.c.
>
> Point (i) is a broken design choice, as I already pointed out.  As for
> (ii), it is a little nicer to take the cdr of each list member without
> checking for stringp.  If others thing this is a really good change, I
> won't object, though it seems pretty trivial to me.  We can add an
> optional flag to the xml-* functions to toggle between the two
> representations.

This patch fixes all the problems above and gives SXML conforming
representation of the elements tree.

Obviously we would need to patch `xml.el', and provide an interface for
accessing tree elements.

Thanks,
Wojciech


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Support-for-SXML-AST.patch --]
[-- Type: text/x-diff, Size: 3263 bytes --]

From 7db230f57fe9b7904d4d55e1fbe90a7522bd38a5 Mon Sep 17 00:00:00 2001
From: Wojciech Meyer <wojciech.meyer@gmail.com>
Date: Thu, 23 Sep 2010 22:45:32 +0100
Subject: [PATCH] Support for SXML AST.

	* xml.c (make_dom): Make output to conform with
	  SXML spec.
	* ChangeLog: Add entry.

Signed-off-by: Wojciech Meyer <wojciech.meyer@gmail.com>
---
 src/ChangeLog |    5 ++++
 src/xml.c     |   60 ++++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 2dd892f..b11d291 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2010-09-23  Wojciech Meyer  <wojciech.meyer@gmail.com>
+
+	* xml.c (make_dom): Make output to conform with
+	  SXML spec.
+
 2010-09-22  Eli Zaretskii  <eliz@gnu.org>
 
 	* editfns.c (Fsubst_char_in_region, Ftranslate_region_internal)
diff --git a/src/xml.c b/src/xml.c
index 5829f1d..9dc0931 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -28,7 +28,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "lisp.h"
 #include "buffer.h"
 
-Lisp_Object make_dom (xmlNode *node)
+static Lisp_Object 
+make_dom (xmlNode *node)
 {
   if (node->type == XML_ELEMENT_NODE)
     {
@@ -36,27 +37,60 @@ Lisp_Object make_dom (xmlNode *node)
       xmlNode *child;
       xmlAttr *property;
       Lisp_Object plist = Qnil;
+      int was_element_node = 0;
+      
+      /* First add the attributes.  */
 
-      /* First add the attributes. */
       property = node->properties;
-      while (property != NULL)
+
+      /* Don't add nil if no properties */
+      if (property != NULL)
 	{
-	  if (property->children &&
-	      property->children->content)
+	  /* Add special `@' node containing properties */
+	  plist = Fcons(intern("@"),Qnil);
+
+	  while (property != NULL)
 	    {
-	      plist = Fcons (Fcons (intern (property->name),
-				    build_string (property->children->content)),
-			     plist);
+	      if (property->children &&
+		  property->children->content)
+		{
+		  plist = 
+		    Fcons 
+		    (Fcons (intern (property->name),
+			    Fcons (build_string (property->children->content), 
+				   Qnil)),
+		     plist);
+		}
+	      property = property->next;
 	    }
-	  property = property->next;
+	  result = Fcons (Fnreverse (plist), result);
 	}
-      result = Fcons (Fnreverse (plist), result);
-
       /* Then add the children of the node. */
+
       child = node->children;
+
+      /* First try to lookup for elements 
+	 if any found, prohibit adding any text elements */
+
       while (child != NULL)
 	{
-	  result = Fcons (make_dom (child), result);
+	  if (child->type == XML_ELEMENT_NODE)
+	    {
+	      was_element_node = 1;
+	      result = Fcons (make_dom (child), result);
+	    }
+
+	  child = child->next;
+	}
+      
+      child = node->children;
+      
+      while (!was_element_node && child != NULL)
+	{
+
+	  if ( child->type == XML_TEXT_NODE )
+	    result = Fcons (make_dom (child), result);
+
 	  child = child->next;
 	}
 
@@ -73,7 +107,7 @@ Lisp_Object make_dom (xmlNode *node)
     return Qnil;
 }
 
-static Lisp_Object
+INLINE static Lisp_Object
 parse_string (Lisp_Object string, Lisp_Object base_url, int htmlp)
 {
   xmlDoc *doc;
-- 
1.7.0.4


  parent reply	other threads:[~2010-09-23 21:58 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-14 18:11 Problems with xml-parse-string Leo
2010-09-14 18:24 ` Lars Magne Ingebrigtsen
2010-09-14 21:18   ` Stefan Monnier
2010-09-15  8:06     ` Lars Magne Ingebrigtsen
2010-09-15  8:51       ` Stefan Monnier
2010-09-15  9:21         ` Lars Magne Ingebrigtsen
2010-09-15  9:54           ` Leo
2010-09-15 10:16             ` Julien Danjou
2010-09-15 15:58               ` Chad Brown
2010-09-21 23:00           ` Chong Yidong
2010-09-21 23:24             ` Leo
2010-09-22  2:26               ` Chong Yidong
2010-09-22  3:15                 ` Chong Yidong
2010-09-22  7:14                   ` Stefan Monnier
2010-09-22 10:35                   ` Lars Magne Ingebrigtsen
2010-09-22 10:58                     ` Lars Magne Ingebrigtsen
2010-09-22 11:00                     ` Leo
2010-09-22 11:09                       ` Lars Magne Ingebrigtsen
2010-09-22 11:41                         ` Lars Magne Ingebrigtsen
2010-09-22 11:55                           ` Wojciech Meyer
2010-09-22 12:09                             ` Lars Magne Ingebrigtsen
2010-09-22 12:17                               ` Wojciech Meyer
2010-09-22 12:18                                 ` Lars Magne Ingebrigtsen
2010-09-22 12:20                                   ` Wojciech Meyer
2010-09-22 12:26                                     ` Lars Magne Ingebrigtsen
2010-09-22 12:34                                       ` Wojciech Meyer
2010-09-22 12:46                                         ` Lars Magne Ingebrigtsen
2010-09-22 12:45                         ` Leo
2010-09-22 13:14                           ` Lars Magne Ingebrigtsen
2010-09-22 14:07                             ` Chong Yidong
2010-09-22 15:04                               ` Eli Zaretskii
2010-09-22 23:59                               ` Stefan Monnier
2010-09-23  5:53                                 ` Leo
2010-09-23 15:43                                   ` Chong Yidong
2010-09-23 16:53                                     ` Leo
2010-09-23 21:58                                     ` Wojciech Meyer [this message]
2010-09-23 22:21                                     ` Lars Magne Ingebrigtsen
2010-09-24  0:04                                       ` Stefan Monnier
2010-09-24  0:06                                         ` Lars Magne Ingebrigtsen
2010-09-24  1:09                                           ` Chong Yidong
2010-09-24  2:46                                             ` David De La Harpe Golden
2010-09-24  5:38                                               ` David Kastrup
2010-09-24  8:02                                               ` Eli Zaretskii
2010-09-24 10:47                                                 ` Wojciech Meyer
2010-09-24 10:44                                             ` Wojciech Meyer
2010-09-24 10:49                                             ` Lars Magne Ingebrigtsen
2010-09-24 15:25                                               ` Chong Yidong
2010-09-24 15:53                                                 ` Lars Magne Ingebrigtsen
2010-09-24 16:26                                                   ` Chong Yidong
2010-09-24 16:46                                                     ` Lars Magne Ingebrigtsen
2010-09-24 17:34                                                       ` Wojciech Meyer
2010-09-24 18:09                                                         ` Frank Schmitt
2010-09-24 18:21                                                           ` Ted Zlatanov
2010-09-24 18:31                                                           ` Wojciech Meyer
2010-09-24 18:47                                                       ` Chong Yidong
2010-09-24 18:53                                                         ` Chong Yidong
2010-09-24 18:58                                                           ` Wojciech Meyer
2010-09-24 19:06                                                         ` Lars Magne Ingebrigtsen
2010-09-24 19:25                                                           ` Chong Yidong
2010-09-24 19:34                                                             ` Lars Magne Ingebrigtsen
2010-09-24 21:57                                                               ` Chong Yidong
2010-09-25 13:11                                                                 ` Lars Magne Ingebrigtsen
2010-09-25 13:31                                                                   ` Eli Zaretskii
2010-09-25 13:56                                                                     ` David Kastrup
2010-09-25 13:59                                                                     ` Wojciech Meyer
2010-09-25 16:13                                                                       ` Eli Zaretskii
2010-09-25 16:46                                                                         ` Wojciech Meyer
2010-09-25 22:29                                                                           ` Juanma Barranquero
2010-09-25 15:00                                                                     ` Chong Yidong
2010-09-24 22:01                                                             ` Stefan Monnier
2010-09-24 22:17                                                               ` Chong Yidong
2010-09-25  0:25                                                                 ` Wojciech Meyer
2010-09-25 14:42                                                       ` Andy Wingo
2010-09-25 15:12                                                         ` Leo
2010-09-25 15:21                                                         ` Leo
2010-09-25 15:42                                                           ` Wojciech Meyer
2010-09-25 20:02                                                             ` Stefan Monnier
2010-09-25 20:32                                                               ` Leo
2010-09-25 23:08                                                               ` Leo
2010-09-26 21:55                                                                 ` Stefan Monnier
2010-09-26 23:34                                                                   ` Leo
2010-09-26  3:48                                                               ` pcase.el (was: Problems with xml-parse-string) Ted Zlatanov
2010-09-26 22:06                                                                 ` pcase.el Stefan Monnier
2010-09-27 16:59                                                                   ` pcase.el Leo
2010-09-27 22:51                                                                     ` pcase.el Stefan Monnier
2010-09-28 18:17                                                                   ` pcase.el Ted Zlatanov
2010-09-24 23:43                                         ` Problems with xml-parse-string Andrew W. Nosenko
2010-09-23  2:16                               ` Kevin Rodgers
2010-09-22 14:05                     ` Chong Yidong
2010-09-22 14:32                       ` Lars Magne Ingebrigtsen
2010-09-22 15:46                         ` Chong Yidong
2010-09-22 16:12                           ` Lars Magne Ingebrigtsen
2010-09-22 16:51                           ` Wojciech Meyer
2010-09-22 18:06                             ` Chong Yidong
2010-09-22 18:14                               ` Edward O'Connor
2010-09-22 18:34                                 ` Leo
2010-09-22 18:41                                   ` Chong Yidong
2010-09-22 19:57                                     ` Wojciech Meyer
2010-09-22 18:06                             ` Andy Wingo
2010-09-22 23:48             ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hbhggm15.fsf@gmail.com \
    --to=wojciech.meyer@googlemail.com \
    --cc=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.org \
    --cc=sdl.web@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.