Mercurial > emacs
comparison lisp/xml.el @ 55253:d33879ad154a
(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.
author | Alex Schroeder <alex@gnu.org> |
---|---|
date | Fri, 30 Apr 2004 20:00:19 +0000 |
parents | 42293f0612cc |
children | 7ac80356d84c |
comparison
equal
deleted
inserted
replaced
55252:fd5403ebeab1 | 55253:d33879ad154a |
---|---|
620 ;;** Printing a tree. | 620 ;;** Printing a tree. |
621 ;;** This function is intended mainly for debugging purposes. | 621 ;;** This function is intended mainly for debugging purposes. |
622 ;;** | 622 ;;** |
623 ;;******************************************************************* | 623 ;;******************************************************************* |
624 | 624 |
625 (defun xml-debug-print (xml) | 625 (defun xml-debug-print (xml &optional indent-string) |
626 "Outputs the XML in the current buffer. | |
627 XML can be a tree or a list of nodes. | |
628 The first line is indented with the optional INDENT-STRING." | |
629 (setq indent-string (or indent-string "")) | |
626 (dolist (node xml) | 630 (dolist (node xml) |
627 (xml-debug-print-internal node ""))) | 631 (xml-debug-print-internal node indent-string))) |
632 | |
633 (defalias 'xml-print 'xml-debug-print) | |
628 | 634 |
629 (defun xml-debug-print-internal (xml indent-string) | 635 (defun xml-debug-print-internal (xml indent-string) |
630 "Outputs the XML tree in the current buffer. | 636 "Outputs the XML tree in the current buffer. |
631 The first line is indented with INDENT-STRING." | 637 The first line is indented with INDENT-STRING." |
632 (let ((tree xml) | 638 (let ((tree xml) |
637 (setq attlist (xml-node-attributes tree)) | 643 (setq attlist (xml-node-attributes tree)) |
638 (while attlist | 644 (while attlist |
639 (insert ?\ (symbol-name (caar attlist)) "=\"" (cdar attlist) ?\") | 645 (insert ?\ (symbol-name (caar attlist)) "=\"" (cdar attlist) ?\") |
640 (setq attlist (cdr attlist))) | 646 (setq attlist (cdr attlist))) |
641 | 647 |
642 (insert ?>) | |
643 | |
644 (setq tree (xml-node-children tree)) | 648 (setq tree (xml-node-children tree)) |
645 | 649 |
646 ;; output the children | 650 (if (null tree) |
647 (dolist (node tree) | 651 (insert ?/ ?>) |
648 (cond | 652 (insert ?>) |
649 ((listp node) | 653 |
650 (insert ?\n) | 654 ;; output the children |
651 (xml-debug-print-internal node (concat indent-string " "))) | 655 (dolist (node tree) |
652 ((stringp node) (insert node)) | 656 (cond |
653 (t | 657 ((listp node) |
654 (error "Invalid XML tree")))) | 658 (insert ?\n) |
655 | 659 (xml-debug-print-internal node (concat indent-string " "))) |
656 (insert ?\n indent-string | 660 ((stringp node) (insert node)) |
657 ?< ?/ (symbol-name (xml-node-name xml)) ?>))) | 661 (t |
662 (error "Invalid XML tree")))) | |
663 | |
664 (when (not (and (null (cdr tree)) | |
665 (stringp (car tree)))) | |
666 (insert ?\n indent-string)) | |
667 (insert ?< ?/ (symbol-name (xml-node-name xml)) ?>)))) | |
658 | 668 |
659 (provide 'xml) | 669 (provide 'xml) |
660 | 670 |
661 ;;; arch-tag: 5864b283-5a68-4b59-a20d-36a72b353b9b | 671 ;;; arch-tag: 5864b283-5a68-4b59-a20d-36a72b353b9b |
662 ;;; xml.el ends here | 672 ;;; xml.el ends here |