From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.lisp.guile.bugs Subject: bug#20339: sxml simple: sxml->xml mishandles namespaces? Date: Mon, 8 Apr 2019 14:14:03 +0200 Message-ID: <20190408121403.GA781@tuxteam.de> References: <20150415194714.GA30295@tuxteam.de> <87y45vln0f.fsf@pobox.com> <20160713132403.GA2349@tuxteam.de> <87furc1qeu.fsf@pobox.com> <87a7jbi8rx.fsf@elephly.net> <874l9iiopl.fsf@elephly.net> <87r2cmgzq0.fsf@elephly.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="yrj/dFKFPuw6o+aM" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="240474"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) Cc: 20339@debbugs.gnu.org To: Ricardo Wurmus Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Mon Apr 08 14:15:21 2019 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hDTBI-0010PG-KJ for guile-bugs@m.gmane.org; Mon, 08 Apr 2019 14:15:20 +0200 Original-Received: from localhost ([127.0.0.1]:52213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDTBH-0004xm-Eh for guile-bugs@m.gmane.org; Mon, 08 Apr 2019 08:15:19 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:49698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDTB5-0004vv-Ed for bug-guile@gnu.org; Mon, 08 Apr 2019 08:15:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDTB3-0007od-O2 for bug-guile@gnu.org; Mon, 08 Apr 2019 08:15:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35531) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hDTB0-0007mN-R1 for bug-guile@gnu.org; Mon, 08 Apr 2019 08:15:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hDTB0-0007Jz-L4 for bug-guile@gnu.org; Mon, 08 Apr 2019 08:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 08 Apr 2019 12:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20339 X-GNU-PR-Package: guile Original-Received: via spool by 20339-submit@debbugs.gnu.org id=B20339.155472565528064 (code B ref 20339); Mon, 08 Apr 2019 12:15:02 +0000 Original-Received: (at 20339) by debbugs.gnu.org; 8 Apr 2019 12:14:15 +0000 Original-Received: from localhost ([127.0.0.1]:49075 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hDTAE-0007IZ-GN for submit@debbugs.gnu.org; Mon, 08 Apr 2019 08:14:14 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:47211) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hDTAB-0007IL-3J for 20339@debbugs.gnu.org; Mon, 08 Apr 2019 08:14:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:Date; bh=9rttPn+Z2+suDJb3cpPrezQSV7+57zD/mpt/BOrh6pg=; b=KNHTOkZxHdP+4ohMcWgeG29Lp9zSZNZqFFkIUR6sD9u63tEVA+2bqq6udxH0xOdUiUGVnADSKxgAwtcd4P+08keYwrPWzt6iv8p+aD1dwBsvwevUWDPIYbz/c55UbPMmqBwO0OITP9RiohTLTiLHLtO1oNmAA6zR1CgqDLRzb2lk5WTcVJ/6PPksOkYZlBIJVar6QDOeO6wUS7WJ7tA62G8fxitrClwh3RjAMIR6NIQApU2IymX1pZj5sNn0EOjEqIM+tlQTXlIHDabHLSQEXnCw94BdxPonDTbFWGID+d+cY6KMARXIaeIu1cLGuS9OHTRAkreb9lEdMaRBndPA/g==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1hDTA3-0000Vy-WB; Mon, 08 Apr 2019 14:14:04 +0200 Content-Disposition: inline In-Reply-To: <87r2cmgzq0.fsf@elephly.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:9311 Archived-At: --yrj/dFKFPuw6o+aM Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Feb 05, 2019 at 01:57:11PM +0100, Ricardo Wurmus wrote: >=20 > Ricardo Wurmus writes: >=20 > > In that case we coud have FINISH-ELEMENT add all namespace declarations > > that are in scope to the current node that is about to be returned. It > > would be a little verbose, but more correct. >=20 > Like this: Thanks again for your patch, and sorry for my glacial pace. I now came around to test it (against Guile 2.2.4, commit 791cae940afcb2b2eb2c167fe438be1dc1008a73). TL;DR: - The default namespace is still a problem (see below) - It would be nice to inhibit the down-inheritance of namespace declararions at xml->sxml time. Then, the sxml representation would closely mimic the XML, this has obvious advantages, since it'd give the user much more control over the generated XML. I'd be willing to prepare a patch along these lines, but for that, I'd like to get an idea of which direction we want to take this whole thing to. To see what's going on, I tried with a small XML example: First with explicit (aka non-default) namespace: #+NAME: minimal-explicit #+BEGIN_EXAMPLE #+END_EXAMPLE Before your patch: #+NAME: minimal-explicit-before #+BEGIN_SRC scheme :results output verbatim :var the-xml=3Dminimal-explic= it (use-modules (sxml simple)) (use-modules (ice-9 pretty-print)) (pretty-print (xml->sxml the-xml)) #+END_SRC #+RESULTS: minimal-explicit-before : :12:0: warning: possibly unbound variable `pretty-print' : :12:14: warning: possibly unbound variable `xml->sxml' : (*TOP* (*PI* xml "version=3D\"1.0\"") : (http://example.org/namespaces/myns:root : "\n " : (http://example.org/namespaces/myns:subnode) : "\n")) As we know, this replaces the namespace prefixes with the namespace URIs After your patch: #+NAME: minimal-explicit-after #+BEGIN_SRC scheme :results output verbatim :var the-xml=3Dminimal-explic= it (set! %load-path (cons "." %load-path)) (use-modules (sxml simple)) (use-modules (ice-9 pretty-print)) (pretty-print (xml->sxml the-xml)) #+END_SRC #+RESULTS: minimal-explicit-after #+begin_example :13:0: warning: possibly unbound variable `pretty-print' :13:14: warning: possibly unbound variable `xml->sxml' ;;; note: source file ./sxml/simple.scm ;;; newer than compiled /usr/local/lib/guile/2.2/ccache/sxml/simple= =2Ego ;;; found fresh local cache at /home/tomas/.cache/guile/ccache/2.2-LE-8-3= =2EA/home/tomas/guile/sxml-fix/sxml/simple.scm.go (*TOP* (*PI* xml "version=3D\"1.0\"") (myns:root (@ (xmlns:myns "http://example.org/namespaces/myns")) "\n " (myns:subnode (@ (xmlns:myns "http://example.org/namespaces/myns"))) "\n")) #+end_example (I've put sxml/simple.scm in the current directory, thus the manipulation of %load-path). This mimics the XML more closely, using namespace prefixes instead of namespaces in the sxml. This is compelling :-) The only difference to the xml is that the namespace declaration is inherit= ed to lower-level nodes (that's why sxml->xml propagates them, too). This works, with the above downside, which you noted too. It doesn't work with a default namespace, though: #+NAME: minimal-implicit #+BEGIN_EXAMPLE #+END_EXAMPLE With your patch: #+NAME: minimal-implicit-after #+BEGIN_SRC scheme :results output verbatim :var the-xml=3Dminimal-implic= it (set! %load-path (cons "." %load-path)) (use-modules (sxml simple)) (use-modules (ice-9 pretty-print)) (pretty-print (xml->sxml the-xml)) #+END_SRC #+RESULTS: minimal-implicit-after : :13:0: warning: possibly unbound variable `pretty-print' : :13:14: warning: possibly unbound variable `xml->sxml' : ;;; note: source file ./sxml/simple.scm : ;;; newer than compiled /usr/local/lib/guile/2.2/ccache/sxml/simp= le.go : ;;; found fresh local cache at /home/tomas/.cache/guile/ccache/2.2-LE-8= -3.A/home/tomas/guile/sxml-fix/sxml/simple.scm.go : (*TOP* (*PI* xml "version=3D\"1.0\"") : (*DEFAULT*:root "\n " (*DEFAULT*:subnode) "\n")) Note that the namespace declaration for *DEFAULT* is missing, so we lost that bit of information. Besides, this is not serializable: #+NAME: reserialize-implicit #+BEGIN_SRC scheme :results output verbatim (set! %load-path (cons "." %load-path)) (use-modules (sxml simple)) (define the-sxml '(*TOP* (*PI* xml "version=3D\"1.0\"") (*DEFAULT*:root "\n " (*DEFAULT*:subnode) "\n"))) (sxml->xml the-sxml) #+END_SRC It catches the bad (xml) name starting with a star: #+RESULTS: reserialize-implicit : ERROR: In procedure scm-error: : Invalid name starting character "*DEFAULT*" *DEFAULT*:root :=20 : Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. : scheme@(guile-user) [1]>=20 Cheers -- tom=C3=A1s --yrj/dFKFPuw6o+aM Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlyrOwsACgkQBcgs9XrR2kabQgCeIvJGAfCZb5KnVNe7M7VFapAY l9kAn110JNoUb3XRLxV8nCAk4ihppgsF =bnBc -----END PGP SIGNATURE----- --yrj/dFKFPuw6o+aM--