Page 1 of 1

CL Printing Strings for use in XML

Posted: Thu Dec 24, 2009 5:57 pm
by inexperienced
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

Re: CL Printing Strings for use in XML

Posted: Fri Dec 25, 2009 12:42 am
by dmitry_vk
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.