[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#20339: sxml simple: sxml->xml mishandles namespaces?
From: |
Ricardo Wurmus |
Subject: |
bug#20339: sxml simple: sxml->xml mishandles namespaces? |
Date: |
Tue, 21 Apr 2015 11:24:03 +0200 |
Hi Tomás,
address@hidden writes:
> When transforming SXML to XML, namespaces don't seem to be handled
> properly:
>
[...]
>
> The problem is that SXML used the concatenated (full) namespace with the
> name as tag (and attribute) names for namespaced items. When serializing
> to XML it should try to find abbreviations for those namespaces and issue
> the corresponding namespace declarations.
>
> Instead, sxml->xml tries to split the (namespace:name) combination
> at the first colon and to check the name -- and fails miserably at
> (namespace:name) combinations à la "http://www.w3.org/1999/xlink:href"
> (procedure check-name). Since there are two colons, the name part
> has now a colon.
xml->sxml has an optional #:namespaces argument, where you can pass an
alist of keys to URLs to be used in the sxml output:
(let* ((ns '((svg . "http://www.w3.org/2000/svg")
(xlink . "http://www.w3.org/1999/xlink")))
(the-sxml (xml->sxml the-svg #:namespaces ns)))
(display the-sxml))
=> (*TOP*
(svg:svg
(svg:rect (@ (y 5)
(x 5)
(width 20)
(stroke-width 2)
(stroke purple)
(id rect1)
(height 20)
(fill yellow)))
(svg:rect (@ (xlink:href #rect1)
(y 5)
(x 30)
(width 20)
(stroke-width 2)
(stroke purple)
(ry 5)
(rx 8)
(height 20)
(fill blue)))))
Passing this to sxml->xml yields:
<svg:svg>
<svg:rect y="5" x="5"
width="20"
stroke-width="2"
stroke="purple"
id="rect1"
height="20"
fill="yellow" />
<svg:rect xlink:href="#rect1"
y="5" x="30"
width="20"
stroke-width="2"
stroke="purple"
ry="5" rx="8"
height="20"
fill="blue" />
</svg:svg>
Unfortunately, sxml->xml will not replace the namespace abbreviations,
nor will it add appropriate xmlns attributes, so "svg" and "xlink" are
devoid of any meaning.
Since xml->sxml accepts a namespace alist I suppose it would make sense
to extend sxml->xml to do the same.
~~ Ricardo