Arc Forumnew | comments | leaders | submitlogin
1 point by Jesin 5855 days ago | link | parent

Messing with XML in general should be pretty easy in Lisp.


1 point by drcode 5855 days ago | link

FYI- In case anyone is doing this, here is my version of the canonical sexp->xml function:

  (def xexp (x (o indent 0))
    (if acons.x
        (withs ((tg . lst) x
	        atts nil
	        pad (apply string (n-of indent " "))
  	      pretty (all acons lst))
  	(and lst (acons caar.lst) (= atts pop.lst))
  	(string pad 
  		"<" 
  		tg 
  		(tostring:map [pr " " car._ "=\"" cdr._ "\""] atts) 
  		">" 
  		(when pretty
  		  "\n")
  		(apply string (map [xexp _ (+ indent 3)] lst)) 
  		(when pretty
  		  pad)
  		"</" 
  		tg 
  		">\n"))
        string.x))
It assumes the standard PLT-scheme "xexpr" format...it is naive about character encoding right now BTW.

Example:

  (xexp '(ying (foo ((bar . baz)) "zing") (yang)))

  <ying>
     <foo bar="baz">zing</foo>
     <yang>
     </yang>
  </ying>
(fyi, 'tag makes html assumptions and breaks on most xml, nor is it really appropriate in style for building xml)

-----