diff options
author | Alex Schroeder <alex@gnu.org> | 2004-04-30 20:00:19 +0000 |
---|---|---|
committer | Alex Schroeder <alex@gnu.org> | 2004-04-30 20:00:19 +0000 |
commit | 27240aa42f922ee7470a5cdfefb896b0867e29b7 (patch) | |
tree | 63cb4198a9ab59cc440ccc144691c4ec3639bebb /lisp/xml.el | |
parent | d71d20ea2ce24b9a8b230ffe1ed1de1aae09adf8 (diff) | |
download | emacs-27240aa42f922ee7470a5cdfefb896b0867e29b7.tar.gz |
(xml-debug-print-internal): Don't add newline and
indentation to text nodes and write empty elements as empty tags
instead of opening and closing tags.
(xml-debug-print): Take optional indent-string argument.
(xml-print): Alias for xml-debug-print.
Diffstat (limited to 'lisp/xml.el')
-rw-r--r-- | lisp/xml.el | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/lisp/xml.el b/lisp/xml.el index ab87125356d..db3292a4cfb 100644 --- a/lisp/xml.el +++ b/lisp/xml.el @@ -622,9 +622,15 @@ This follows the rule [28] in the XML specifications." ;;** ;;******************************************************************* -(defun xml-debug-print (xml) +(defun xml-debug-print (xml &optional indent-string) + "Outputs the XML in the current buffer. +XML can be a tree or a list of nodes. +The first line is indented with the optional INDENT-STRING." + (setq indent-string (or indent-string "")) (dolist (node xml) - (xml-debug-print-internal node ""))) + (xml-debug-print-internal node indent-string))) + +(defalias 'xml-print 'xml-debug-print) (defun xml-debug-print-internal (xml indent-string) "Outputs the XML tree in the current buffer. @@ -639,22 +645,26 @@ The first line is indented with INDENT-STRING." (insert ?\ (symbol-name (caar attlist)) "=\"" (cdar attlist) ?\") (setq attlist (cdr attlist))) - (insert ?>) - (setq tree (xml-node-children tree)) - ;; output the children - (dolist (node tree) - (cond - ((listp node) - (insert ?\n) - (xml-debug-print-internal node (concat indent-string " "))) - ((stringp node) (insert node)) - (t - (error "Invalid XML tree")))) - - (insert ?\n indent-string - ?< ?/ (symbol-name (xml-node-name xml)) ?>))) + (if (null tree) + (insert ?/ ?>) + (insert ?>) + + ;; output the children + (dolist (node tree) + (cond + ((listp node) + (insert ?\n) + (xml-debug-print-internal node (concat indent-string " "))) + ((stringp node) (insert node)) + (t + (error "Invalid XML tree")))) + + (when (not (and (null (cdr tree)) + (stringp (car tree)))) + (insert ?\n indent-string)) + (insert ?< ?/ (symbol-name (xml-node-name xml)) ?>)))) (provide 'xml) |