The escXml function could be like this:

(de escXml (X)
   (for C (chop X)
      (prin (case C
               ("\"" """)
               ("&" "&")
               ("<" "&lt;")
               (">" "&gt;")
               (T C) ) ) ) )

> It is probably best to automatically escape attributes but leave the
> user to escape body (as attributes will be usually a value while body
> will come via prin or something).

The body should be printed using ht:Prin to get good escaping.

>>> Since this is "pure" XML, it would seem natural to find a function like 
>>> this <xml> in lib/xml.l. I haven't studied the functions in that file 
>> Tomas also suggested this. I think it is a good idea. I would like to

Actually, the more I think about it the less I like it.  It just
introduces some questions with application specific answers only.
Maybe it should not be in the picoLisp distribution after all?

Or, what about reusing the 'xml' function instead of duplicating it:

(de <xml> Lst
   (let Tag (pop 'Lst)
      (if Tag
         (queue '*Xml
               (link Tag)
               (let A
                     (while (and Lst (atom (car Lst)))
                        (link (cons (pop 'Lst) (eval (pop 'Lst) 1))) ) )
                  (let *Xml NIL
                     (run Lst)
                     (ifn *Xml
                        (when A
                           (link A) )
                        (link A)
                        (chain *Xml) ) ) ) ) )
         (let *Xml NIL
            (run Lst)
            (xml (car *Xml) ) ) ) ) )
(de xmlPrin @
   (queue '*Xml (pass pack)) )

(<xml> NIL
   (<xml> hoy id 123 class 'yes
      (<xml> inner1)
      (<xml> text id 123 dx (+ 3 4) dy (* 3 4)
         xx "you & me"
         yy "<![CDATA[\"Me, Myself & <I>\"]]>"
         (xmlPrin "No font & color arguments yet") )
      (<xml> inner2 fun "abc"
         (xmlPrin "Hi 1 asfdlkasjhfdshad")
         (<xml> line x 0 y 0 dx 100 dy 100
            (xmlPrin "thick"))
         (xmlPrin "Hi 2") )
      (<xml> inner3 fun "abc") ) )

The only problem with this code is that the body is not run in the
parent environment, which I don't know how to fix or what problems it
could cause.

Alex, is it more efficient to use push together with reverse or is
queue fine?



Reply via email to