CL Printing Strings for use in XML

Discussion of Common Lisp
Post Reply
inexperienced
Posts: 7
Joined: Wed Dec 16, 2009 2:07 pm

CL Printing Strings for use in XML

Post by inexperienced » Thu Dec 24, 2009 5:57 pm

Hello!

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*
    (formatter 
     "<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=""stamps""/> ...


is there a straightforward way to do this?
Thanks
inexperienced

dmitry_vk
Posts: 96
Joined: Sat Jun 28, 2008 8:01 am
Location: Russia, Kazan
Contact:

Re: CL Printing Strings for use in XML

Post by dmitry_vk » Fri Dec 25, 2009 12:42 am

It is much better and simpler to use CL-WHO (http://weitz.de/cl-who/) or CXML (http://common-lisp.net/project/cxml/sax ... ialization) to generate XML.

Post Reply