Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

which library to generate xml with namespaces?

26 views
Skip to first unread message

Mirko

unread,
Jun 17, 2010, 10:31:31 PM6/17/10
to
Hello,

I need to generate xml tags of the following type:

<diagram xmlns:dia="http://www.lysator.liu.se/~alla/dia/">

i.e. with the xmlns namespace. Which library can do that (cl-who does
not seem to be able to)?

Thanks,

Mirko

Pascal J. Bourguignon

unread,
Jun 18, 2010, 6:01:25 AM6/18/10
to
Mirko <mirko....@gmail.com> writes:


xmls can generate XML with namespaces:

(xmls:toxml '("diagram" (("xmlns:dia" "http://www.lysator.liu.se/~alla/dia/"))))
--> "<diagram xmlns:dia=\"http://www.lysator.liu.se/~alla/dia/\"/>"

It ignores them when parsing, but I guess this is something that could
easily be modified.

--
__Pascal Bourguignon__ http://www.informatimago.com/

Olof-Joachim Frahm

unread,
Jun 18, 2010, 9:04:21 AM6/18/10
to
Hi Mirko,

you can actually do that with CL-WHO: by using the following syntax for
the attribute:
> (cl-who:with-html-output (*standard-output* NIL)
> (:diagram :|xmlns:dia| "http://www.lysator.liu.se/~alla/dia/"))
or (because I also looked for this feature) by hacking CL-WHO to use
for example the following cons syntax, which to my knowledge isn't used
for anything in the unpatched library:
> (cl-who:with-html-output (*standard-output*)
> (:diagram (:xmlns . :dia) "http://www.lysator.liu.se/~alla/dia/"))

If that suits you, the fork and a bit of documentation is available from
<http://github.com/Ferada/cl-who>.

Cheers,
Olof

--
The world is burning. Run.

Frode V. Fjeld

unread,
Jul 1, 2010, 7:14:57 AM7/1/10
to
Mirko <mirko....@gmail.com> writes:

I just got around to upload this library which perhaps does what you
need: http://github.com/frodef/pithy-xml

Here's an intro session:

PITHY-XML> (define-xml-namespace dia "http://www.lysator.liu.se/~alla/dia/")
DIA
PITHY-XML> (read-xml "<diagram xmlns:dia='http://www.lysator.liu.se/~alla/dia/' />")
(:DIAGRAM XMLNS::DIA "http://www.lysator.liu.se/~alla/dia/")
PITHY-XML> (print-xml *)
"<Diagram xmlns:dia='http://www.lysator.liu.se/~alla/dia/'/>"
PITHY-XML>

--
Frode V. Fjeld

Mirko

unread,
Jul 1, 2010, 9:23:19 AM7/1/10
to
On Jul 1, 7:14 am, "Frode V. Fjeld" <fro...@cs.uit.no> wrote:

Thanks. I am right now using xmls, but will take a look at this
package.

Mirko

Rupert Swarbrick

unread,
Jul 2, 2010, 6:30:45 AM7/2/10
to
"Frode V. Fjeld" <fro...@cs.uit.no> writes:
> I just got around to upload this library which perhaps does what you
> need: http://github.com/frodef/pithy-xml
>
> Here's an intro session:
>
> PITHY-XML> (define-xml-namespace dia "http://www.lysator.liu.se/~alla/dia/")
> DIA
> PITHY-XML> (read-xml "<diagram xmlns:dia='http://www.lysator.liu.se/~alla/dia/' />")
> (:DIAGRAM XMLNS::DIA "http://www.lysator.liu.se/~alla/dia/")
> PITHY-XML> (print-xml *)
> "<Diagram xmlns:dia='http://www.lysator.liu.se/~alla/dia/'/>"

Does it really give "Diagram" (with this capitalisation)? Wouldn't that
be a bug?

Rupert

Frode V. Fjeld

unread,
Jul 2, 2010, 6:45:57 AM7/2/10
to
Rupert Swarbrick <rswar...@gmail.com> writes:

> Does it really give "Diagram" (with this capitalisation)? Wouldn't
> that be a bug?

Well.. this behavior happened to fit my requirements at the time. There
are quite a few ways that can be used to convert :DIAGRAM (or more
generally :SOME-DIAGRAM) to an XML-ish string (and back). I suppose the
solution would be to implement and support them all and set behavior per
namespace. I won't have time for this in the immediate future,
however. Unless I'll happen to need it..

BTW I was aiming for a syntax that was convenient to use from the lisp
side. As opposed to require lisp symbols such ash :|someDiagram| etc.

--
Frode V. Fjeld

Thomas A. Russ

unread,
Jul 2, 2010, 2:38:36 PM7/2/10
to

Unfortunately, xml is case-sensitive, so reading a tag <diagram...> and
turning it into <Diagram...> is an error.

Perhaps the solution would be to use READTABLE-CASE = :PRESERVE when you
read and write the XML. That will give you keywords like :|diagram|,
but generally if READTABLE-CASE is :PRESERVE, it will print without the
vertical bars.

(let* ((csrt (copy-readtable))
(*readtable* csrt))
(setf (readtable-case csrt) :preserve)
(print (read-from-string "(:digaram :xmlns dia Fred)"))
(terpri))

(:digaram :xmlns dia Fred)

(:|digaram| :|xmlns| |dia| |Fred|)

Of course, you will have to use all uppercase for standard lisp names.

An alternative may be to use :INVERT as the readtable case.


--
Thomas A. Russ, USC/Information Sciences Institute

Frode V. Fjeld

unread,
Jul 2, 2010, 4:57:46 PM7/2/10
to
t...@sevak.isi.edu (Thomas A. Russ) writes:

> Unfortunately, xml is case-sensitive, so reading a tag <diagram...> and
> turning it into <Diagram...> is an error.

Yes. I believe that translating from a cased string to a typical
mono-case-hyphened willl have to be lossy. However I believe most
applications/namespaces employs some case convention that can be dealt
with. My approach would be to support that on a per-namespace basis.

--
Frode V. Fjeld

Thomas A. Russ

unread,
Jul 2, 2010, 6:53:47 PM7/2/10
to
"Frode V. Fjeld" <fr...@netfonds.no> writes:

But wouldn't it be easier for both you as the supporter and for users to
just do it right from the beginning? If you preserved the case of the
tags when you read them in, then you could write them out the way they
are supposed to be without having to do anything special at all for
particular namespaces.

In other words, if you just use the convention that all namespaces are
case-preserving then you will have solved the problem once and for all.

Frode V. Fjeld

unread,
Jul 3, 2010, 6:09:03 AM7/3/10
to

I did consider that. The problem is that not all (or even "most")
processing is of the type that reads in XML, processes it, and spits it
out again. I believe it's more common to just generate some XML from
other information, or to read in XML as input to some process. In other
words, there usually won't be an original casing to preserve.

--
Frode V. Fjeld

0 new messages