summaryrefslogtreecommitdiff
path: root/lisp/xml.el
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2012-08-20 07:34:41 -0600
committerTom Tromey <tromey@redhat.com>2012-08-20 07:34:41 -0600
commit49bc1a9dfc6e81a370bf12157c3c573743ee200a (patch)
tree24df8b040aff367adc11a2c676334ec238651e1d /lisp/xml.el
parentb94de893429bbfbb27572c8c3118fcc876957adb (diff)
parenta05731a0cc2553af0469bd9b7d6ac10cd2e6a817 (diff)
downloademacs-49bc1a9dfc6e81a370bf12157c3c573743ee200a.tar.gz
emacs-49bc1a9dfc6e81a370bf12157c3c573743ee200a.tar.bz2
emacs-49bc1a9dfc6e81a370bf12157c3c573743ee200a.zip
Merge from trunk
Diffstat (limited to 'lisp/xml.el')
-rw-r--r--lisp/xml.el26
1 files changed, 19 insertions, 7 deletions
diff --git a/lisp/xml.el b/lisp/xml.el
index 179fdd6b5cc..d395f75ec0f 100644
--- a/lisp/xml.el
+++ b/lisp/xml.el
@@ -1011,13 +1011,25 @@ The first line is indented with the optional INDENT-STRING."
(defalias 'xml-print 'xml-debug-print)
(defun xml-escape-string (string)
- "Return STRING with entity substitutions made from `xml-entity-alist'."
- (mapconcat (lambda (byte)
- (let ((char (char-to-string byte)))
- (if (rassoc char xml-entity-alist)
- (concat "&" (car (rassoc char xml-entity-alist)) ";")
- char)))
- string ""))
+ "Convert STRING into a string containing valid XML character data.
+Replace occurrences of &<>'\" in STRING with their default XML
+entity references (e.g. replace each & with &amp;).
+
+XML character data must not contain & or < characters, nor the >
+character under some circumstances. The XML spec does not impose
+restriction on \" or ', but we just substitute for these too
+\(as is permitted by the spec)."
+ (with-temp-buffer
+ (insert string)
+ (dolist (substitution '(("&" . "&amp;")
+ ("<" . "&lt;")
+ (">" . "&gt;")
+ ("'" . "&apos;")
+ ("\"" . "&quot;")))
+ (goto-char (point-min))
+ (while (search-forward (car substitution) nil t)
+ (replace-match (cdr substitution) t t nil)))
+ (buffer-string)))
(defun xml-debug-print-internal (xml indent-string)
"Outputs the XML tree in the current buffer.