aboutsummaryrefslogtreecommitdiffhomepage
path: root/generic/pg-xml.el
diff options
context:
space:
mode:
authorGravatar David Aspinall <da@inf.ed.ac.uk>2002-11-28 12:43:40 +0000
committerGravatar David Aspinall <da@inf.ed.ac.uk>2002-11-28 12:43:40 +0000
commit78c1f3571edc406bebcd54217b9656ed1ffd6b8d (patch)
tree0cce9a1492e42e15be189d9af67cc7232ab077ca /generic/pg-xml.el
parent2b89a21f04633cc39e78ba3f8b59cd4d100a464d (diff)
Add pg-xml-encode-entities.
Diffstat (limited to 'generic/pg-xml.el')
-rw-r--r--generic/pg-xml.el11
1 files changed, 11 insertions, 0 deletions
diff --git a/generic/pg-xml.el b/generic/pg-xml.el
index 9fab3903..7f0d48e1 100644
--- a/generic/pg-xml.el
+++ b/generic/pg-xml.el
@@ -183,6 +183,7 @@ is
;;
;; Producing functions: state-based writing of an XML doc,
;; built up in pg-xml-doc
+;;
(defconst pg-xml-header
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
@@ -196,6 +197,16 @@ is
(defvar pg-xml-indentp nil
"Whether to indent written XML documents")
+(defun pg-xml-encode-entities (string)
+ (progn
+ ;; rather inefficiently...
+ (setq string (replace-regexp-in-string (regexp-quote "<") "&lt;" string))
+ (setq string (replace-regexp-in-string (regexp-quote ">") "&rt;" string))
+ (setq string (replace-regexp-in-string (regexp-quote "'") "&apos;" string))
+ (setq string (replace-regexp-in-string (regexp-quote "&") "&amp;" string))
+ (setq string (replace-regexp-in-string (regexp-quote "\"") "&quot;" string))
+ string))
+
(defun pg-xml-begin-write (&optional header)
"Start writing an XML document. If HEADER is non-nil, add <?xml ?>"
(setq pg-xml-doc (if header (list pg-xml-header))