CL Printing Strings for use in XML

Discussion of Common Lisp

CL Printing Strings for use in XML

Postby inexperienced » Thu Dec 24, 2009 5:57 pm


I am working on a project where (among other things) we are writing a list of pairs of values to be embedded in an xml document. Sometimes both members of the pair are symbols; and sometimes they are a symbol and a string. The overall lisp program is quite large. The example shown below is simplified to the essential problem area.

I have not yet found a successful way to write the string in a way that works for XML. So far, here is what I have:

Code: Select all
(defconstant *xml-print-pairs*
     "<chunk name=\"~S\">~:[ (~s)~;~*~]~%~@[~S~%~]  <isa value=\"~S\"/>~%~:{  <slot name=\"~s\" value=\"~s\"/>~%~}</chunk>")
  "compiled format string for printing chunks in xml format")
(format stream-out *xml-print-pairs* chunk-name my-pairs)

Everythings works fine when both members of the pair are symbols.
The problem is that when the second item in the pair is a string, the output has double quotation marks which is not allowed in XML.
For example, if the pair consists of: buyer "stamps", then my output is:
... <slot name="buyer" value=""stamps""/> ...

My desired output in this case would instead be:
... <slot name="buyer" value="&quot;stamps&quot;"/> ...

is there a straightforward way to do this?
Posts: 7
Joined: Wed Dec 16, 2009 2:07 pm

Re: CL Printing Strings for use in XML

Postby dmitry_vk » Fri Dec 25, 2009 12:42 am

It is much better and simpler to use CL-WHO ( or CXML ( ... ialization) to generate XML.
Posts: 96
Joined: Sat Jun 28, 2008 8:01 am
Location: Russia, Kazan

Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 4 guests