1
#| rep.xml.printer -- companion XML printer to rep.xml.reader
3
$Id: printer.jl,v 1.1 2002/06/21 05:11:50 jsh Exp $
5
Copyright (C) 2002 John Harper <jsh@unfactored.org>
7
This file is part of librep.
9
librep is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2, or (at your option)
14
librep is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with librep; see the file COPYING. If not, write to
21
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
(define-structure rep.xml.printer
26
(export make-xml-output
32
(define make-xml-output identity)
34
(define (substitute-entities string)
35
(string-replace "[<&'\"]"
37
(car (rassoc (expand-last-match "\\0")
44
(define (print-params stream params)
46
(format stream " %s=\"%s\""
47
(car cell) (substitute-entities (cdr cell))))
50
(define (print-xml-item stream item)
52
(write stream (substitute-entities item)))
55
(format stream "<!%s>" (nth 1 stream)))
58
(format stream "<%s" (car item))
59
(print-params stream (nth 1 item))
60
(cond ((string-match "^\\?" (symbol-name (car item)))
62
((null (nthcdr 2 item))
67
(print-xml-item stream x)) (nthcdr 2 item))
68
(format stream "</%s>" (car item)))))
70
(t (error "Unknown item type: %s" item)))))