From 7db230f57fe9b7904d4d55e1fbe90a7522bd38a5 Mon Sep 17 00:00:00 2001 From: Wojciech Meyer 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 --- 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 + + * xml.c (make_dom): Make output to conform with + SXML spec. + 2010-09-22 Eli Zaretskii * 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 . */ #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