From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ricardo Wurmus Newsgroups: gmane.lisp.guile.devel Subject: Re: sxml simple, sxml->xml and namespaces Date: Mon, 20 Jun 2016 12:52:47 +0200 Message-ID: <87d1ncdtds.fsf@elephly.net> References: <20150408205527.GA14675@tuxteam.de> <87mvmgjl1h.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1466420002 10963 80.91.229.3 (20 Jun 2016 10:53:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 20 Jun 2016 10:53:22 +0000 (UTC) Cc: guile-devel@gnu.org To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jun 20 12:53:12 2016 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bEwpI-0006gw-4u for guile-devel@m.gmane.org; Mon, 20 Jun 2016 12:53:08 +0200 Original-Received: from localhost ([::1]:42647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEwpC-0005pC-4J for guile-devel@m.gmane.org; Mon, 20 Jun 2016 06:53:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEwp6-0005cW-O0 for guile-devel@gnu.org; Mon, 20 Jun 2016 06:52:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bEwp3-0008Ih-Hf for guile-devel@gnu.org; Mon, 20 Jun 2016 06:52:56 -0400 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:24872) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEwp3-0008Ib-78 for guile-devel@gnu.org; Mon, 20 Jun 2016 06:52:53 -0400 Original-Received: from localhost (x5f72fdfa.dyn.telefonica.de [95.114.253.250]) by mx.zohomail.com with SMTPS id 14664199716733.434049561835195; Mon, 20 Jun 2016 03:52:51 -0700 (PDT) User-agent: mu4e 0.9.16; emacs 24.5.1 In-reply-to: <87mvmgjl1h.fsf@pobox.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 74.201.84.163 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:18365 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Andy Wingo writes: > Apologies for the long delay here. I'm with you regarding namespaces > and sxml->xml. In the past I made sure to always get the namespaces > attached to the root element via the @ xmlns attributes, and then have > namespaced uses just be local names, not qnames, and that way sxml->xml > works fine. But, perhaps that doesn't cover all cases in a nice way. > Do you still have thoughts on this patch? Is the right thing for you? > In any case we need better documentation in the manual about how to deal > with namespaces and SXML, in practice, with examples. Here is another proposal, mirroring what is done in “xml->sxml”: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-sxml-Write-XML-namespaces-when-serializing.patch >From 845badc7d4b748bc13c532e940b8a18ffb10f426 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Sun, 30 Aug 2015 10:57:00 +0200 Subject: [PATCH] sxml: Write XML namespaces when serializing. * module/sxml/simple.scm (sxml->xml): Add optional keyword argument "namespaces". --- module/sxml/simple.scm | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/module/sxml/simple.scm b/module/sxml/simple.scm index 703ad91..8cc20dd 100644 --- a/module/sxml/simple.scm +++ b/module/sxml/simple.scm @@ -311,7 +311,8 @@ port." (display str port) (display "?>" port)) -(define* (sxml->xml tree #:optional (port (current-output-port))) +(define* (sxml->xml tree #:optional (port (current-output-port)) #:key + (namespaces '())) "Serialize the sxml tree @var{tree} as XML. The output will be written to the current output port, unless the optional argument @var{port} is present." @@ -322,7 +323,7 @@ present." (let ((tag (car tree))) (case tag ((*TOP*) - (sxml->xml (cdr tree) port)) + (sxml->xml (cdr tree) port #:namespaces namespaces)) ((*ENTITY*) (if (and (list? (cdr tree)) (= (length (cdr tree)) 1)) (entity->xml (cadr tree) port) @@ -335,10 +336,16 @@ present." (let* ((elems (cdr tree)) (attrs (and (pair? elems) (pair? (car elems)) (eq? '@ (caar elems)) - (cdar elems)))) - (element->xml tag attrs (if attrs (cdr elems) elems) port))))) + (cdar elems))) + (xmlns (map (lambda (x) + (cons (symbol-append 'xmlns: (car x)) + (cdr x))) + namespaces))) + (element->xml tag + (if attrs (append xmlns attrs) xmlns) + (if attrs (cdr elems) elems) port))))) ;; A nodelist. - (for-each (lambda (x) (sxml->xml x port)) tree))) + (for-each (lambda (x) (sxml->xml x port #:namespaces namespaces)) tree))) ((string? tree) (string->escaped-xml tree port)) ((null? tree) *unspecified*) -- 2.8.4 --=-=-= Content-Type: text/plain ~~ Ricardo --=-=-=--