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: Tue, 21 Jun 2016 22:36:18 +0200 Message-ID: <87k2hi1dq5.fsf@elephly.net> References: <20150408205527.GA14675@tuxteam.de> <87mvmgjl1h.fsf@pobox.com> <87d1ncdtds.fsf@elephly.net> <87porchxfl.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1466541426 3989 80.91.229.3 (21 Jun 2016 20:37:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 21 Jun 2016 20:37:06 +0000 (UTC) Cc: guile-devel@gnu.org To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Jun 21 22:36:58 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 1bFSPh-0006jM-Gv for guile-devel@m.gmane.org; Tue, 21 Jun 2016 22:36:49 +0200 Original-Received: from localhost ([::1]:54138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFSPg-0006oS-O6 for guile-devel@m.gmane.org; Tue, 21 Jun 2016 16:36:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFSPS-0006oF-Qu for guile-devel@gnu.org; Tue, 21 Jun 2016 16:36:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFSPO-00030C-JD for guile-devel@gnu.org; Tue, 21 Jun 2016 16:36:33 -0400 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:24178) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFSPO-000302-AL for guile-devel@gnu.org; Tue, 21 Jun 2016 16:36:30 -0400 Original-Received: from localhost (x4d0cee07.dyn.telefonica.de [77.12.238.7]) by mx.zohomail.com with SMTPS id 146654138409480.32375286698812; Tue, 21 Jun 2016 13:36:24 -0700 (PDT) User-agent: mu4e 0.9.16; emacs 24.5.1 In-reply-to: <87porchxfl.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:18383 Archived-At: Andy Wingo writes: > On Mon 20 Jun 2016 12:52, Ricardo Wurmus writes: > >> 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”: > > Neat! Can you elaborate on how it is supposed to work? In a final form > it would need documentation, tests, and an update to the docstring, but > I'd be interested in some xml->sxml->xml round trips as an example. This is the same patch I sent to the discussion of bug#20339 about a year ago. The patch is not very ambitious: it only gives the user a way around the error by letting them pass an alist of namespaces. The patched “sxml->xml” does not attempt to be smart about anything. It will still fail if it encounters an undeclared namespace. My primary goal was to get around the error. Maybe “sxml->xml” really should be smarter than that. What follows is a copy of my original message: >> Since xml->sxml accepts a namespace alist I suppose it would make sense >> to extend sxml->xml to do the same. Attached is a minimal patch to extend "sxml->xml" such that it accepts an optional keyword argument "namespaces" with an alist of prefixes to URLs, analogous to "xml->sxml". When the namespaces alist is provided, "xmlns:prefix=url" attributes are prepended to the element's list of attributes. ;; Define SVG document with namespaces (define the-svg " ") ;; Define alist of namespaces (define ns '((svg . "http://www.w3.org/2000/svg") (xlink . "http://www.w3.org/1999/xlink"))) ;; Convert to SXML, abbreviate namespaces according to ns alist (define the-sxml (xml->sxml the-svg #:namespaces ns)) ;; Convert back to XML (sxml->xml the-sxml #:namespaces ns) => ~~ Ricardo