From: Ricardo Wurmus <rekado@elephly.net>
To: John Cowan <cowan@ccil.org>
Cc: 20339@debbugs.gnu.org
Subject: bug#20339: sxml simple: sxml->xml mishandles namespaces?
Date: Tue, 05 Feb 2019 13:57:11 +0100 [thread overview]
Message-ID: <87r2cmgzq0.fsf@elephly.net> (raw)
In-Reply-To: <874l9iiopl.fsf@elephly.net>
[-- Attachment #1: Type: text/plain, Size: 254 bytes --]
Ricardo Wurmus <rekado@elephly.net> writes:
> 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.
Like this:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-sxml-xml-sxml-Record-and-use-namespace-abbreviations.patch --]
[-- Type: text/x-patch, Size: 3493 bytes --]
From d44c702718baea4c4557d12ca8dd7dab724c7fb6 Mon Sep 17 00:00:00 2001
From: Ricardo Wurmus <rekado@elephly.net>
Date: Mon, 4 Feb 2019 21:39:06 +0100
Subject: [PATCH] sxml: xml->sxml: Record and use namespace abbreviations.
* module/sxml/simple.scm (xml->sxml)
[name->sxml]: Accept namespaces argument to look up abbreviation.
Return name with abbreviation prefix.
[parser]: Let FINISH-ELEMENT procedure return namespaces in addition to
the SXML tree's attributes.
---
module/sxml/simple.scm | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/module/sxml/simple.scm b/module/sxml/simple.scm
index 703ad9137..2bb332c83 100644
--- a/module/sxml/simple.scm
+++ b/module/sxml/simple.scm
@@ -1,7 +1,8 @@
;;;; (sxml simple) -- a simple interface to the SSAX parser
;;;;
-;;;; Copyright (C) 2009, 2010, 2013 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009, 2010, 2013, 2019 Free Software Foundation, Inc.
;;;; Modified 2004 by Andy Wingo <wingo at pobox dot com>.
+;;;; Modified 2019 by Ricardo Wurmus <rekado@elephly.net>.
;;;; Originally written by Oleg Kiselyov <oleg at pobox dot com> as SXML-to-HTML.scm.
;;;;
;;;; This library is free software; you can redistribute it and/or
@@ -30,6 +31,7 @@
#:use-module (sxml ssax)
#:use-module (sxml transform)
#:use-module (ice-9 match)
+ #:use-module (srfi srfi-1)
#:use-module (srfi srfi-13)
#:export (xml->sxml sxml->xml sxml->string))
@@ -123,10 +125,15 @@ port."
(acons '*DEFAULT* default-entity-handler entities)
entities))
- (define (name->sxml name)
+ (define (name->sxml name namespaces)
(match name
((prefix . local-part)
- (symbol-append prefix (string->symbol ":") local-part))
+ (let ((abbrev (and=> (find (match-lambda
+ ((abbrev uri . rest)
+ (and (eq? uri prefix) abbrev)))
+ namespaces)
+ first)))
+ (symbol-append abbrev (string->symbol ":") local-part)))
(_ name)))
(define (doctype-continuation seed)
@@ -150,12 +157,21 @@ port."
(let ((seed (if trim-whitespace?
(ssax:reverse-collect-str-drop-ws seed)
(ssax:reverse-collect-str seed)))
- (attrs (attlist-fold
- (lambda (attr accum)
- (cons (list (name->sxml (car attr)) (cdr attr))
- accum))
- '() attributes)))
- (acons (name->sxml elem-gi)
+ (attrs (append
+ ;; Namespace declarations
+ (filter-map (match-lambda
+ (('*DEFAULT* . _) #f)
+ ((abbrev uri . _)
+ (list (symbol-append 'xmlns: abbrev)
+ (symbol->string uri))))
+ namespaces)
+ (attlist-fold
+ (lambda (attr accum)
+ (cons (list (name->sxml (car attr) namespaces)
+ (cdr attr))
+ accum))
+ '() attributes))))
+ (acons (name->sxml elem-gi namespaces)
(if (null? attrs)
seed
(cons (cons '@ attrs) seed))
--
2.20.1
[-- Attachment #3: Type: text/plain, Size: 119 bytes --]
It’s quite verbose because it doesn’t check if a namespace declaration
is the same in a parent.
--
Ricardo
next prev parent reply other threads:[~2019-02-05 12:57 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-15 19:47 bug#20339: sxml simple: sxml->xml mishandles namespaces? tomas
2015-04-20 7:45 ` bug#20339: [PATCH] sxml->xml and namespaces: updated patch tomas
2015-04-21 9:24 ` bug#20339: sxml simple: sxml->xml mishandles namespaces? Ricardo Wurmus
2015-04-21 9:44 ` tomas
2015-04-22 14:29 ` Ricardo Wurmus
2015-04-23 6:57 ` tomas
2015-04-23 7:04 ` Ricardo Wurmus
2015-04-23 7:40 ` tomas
2015-04-25 20:25 ` tomas
2015-04-26 10:28 ` tomas
2016-06-23 19:32 ` Andy Wingo
2016-07-13 13:24 ` tomas
2016-07-13 18:08 ` tomas
2016-07-14 10:10 ` Andy Wingo
2016-07-14 10:26 ` tomas
2019-02-04 20:44 ` Ricardo Wurmus
2019-02-04 22:55 ` John Cowan
2019-02-05 9:12 ` Ricardo Wurmus
2019-02-05 12:57 ` Ricardo Wurmus [this message]
2019-04-08 12:14 ` tomas
2019-02-12 9:56 ` tomas
2019-02-12 20:30 ` Ricardo Wurmus
2019-05-03 10:46 ` bug#20339: Taking a step back (was: sxml simple: sxml->xml mishandles namespaces?) tomas
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
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r2cmgzq0.fsf@elephly.net \
--to=rekado@elephly.net \
--cc=20339@debbugs.gnu.org \
--cc=cowan@ccil.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).