unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alex Schroeder <alex@emacswiki.org>
Subject: xml.el
Date: Wed, 28 Apr 2004 02:29:56 +0200	[thread overview]
Message-ID: <87isfl54hn.fsf_-_@emacswiki.org> (raw)
In-Reply-To: <E1BG3Ox-00086z-00@surf.glug.org> (Thien-Thi Nguyen's message of "Wed, 21 Apr 2004 00:07:35 +0200")

What do you think of the following patch?
I could install it if nobody objects.

It allows me to produce the following XML:

    <foaf:knows>
      <foaf:Person>
        <foaf:name>Sacha Chua</foaf:name>
        <foaf:homape>http://sacha.free.net.ph</foaf:homape>
        <foaf:mbox>sacha@free.net.ph</foaf:mbox>
        <rdfs:seeAlso rdf:resource="http://sacha.free.net.ph/notebook/xml/foaf.rdf"/>
      </foaf:Person>
    </foaf:knows>

Compare this with the old code:

    <foaf:knows>
      <foaf:Person>
        <foaf:name>Sacha Chua
        </foaf:name>
        <foaf:homape>http://sacha.free.net.ph
        </foaf:homape>
        <foaf:mbox>sacha@free.net.ph
        </foaf:mbox>
        <rdfs:seeAlso rdf:resource="http://sacha.free.net.ph/notebook/xml/foaf.rdf">
        </rdfs:seeAlso>
      </foaf:Person>
    </foaf:knows>

Differences:

1. For text nodes, the closing tag comes right after the text, not on
   a new line.  Example above: foaf:name.

2. For empty elements, we don't use separate open and close tags.
   Example above: rdfs:seeAlso.

I find the functionality very useful, btw, and don't think that we
need to call them "xml-debug-print" and "xml-debug-print-internal".  I
suggest "xml-print" with an optional argument indent-string defaulting
to the empty string.  The old names can stay as wrappers, if required.
I could send a second patch to do that.


2004-04-28  Alex Schroeder  <alex@gnu.org>

	* xml.el (xml-debug-print-internal): Fix handling of closing
          tags for text elements and empty elements.

Index: xml.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/xml.el,v
retrieving revision 1.33
diff -c -r1.33 xml.el
*** xml.el	16 Apr 2004 22:46:26 -0000	1.33
--- xml.el	28 Apr 2004 00:21:47 -0000
***************
*** 639,660 ****
        (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)) ?>)))
  
  (provide 'xml)
  
--- 639,664 ----
        (insert ?\  (symbol-name (caar attlist)) "=\"" (cdar attlist) ?\")
        (setq attlist (cdr attlist)))
  
      (setq tree (xml-node-children tree))
  
!     (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)

  reply	other threads:[~2004-04-28  0:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-20 13:57 emacs 21.2 cvs tag? Thien-Thi Nguyen
2004-04-20 14:00 ` David Kastrup
2004-04-20 22:07   ` Thien-Thi Nguyen
2004-04-28  0:29     ` Alex Schroeder [this message]
2004-04-29 20:10       ` xml.el Stefan Monnier
2004-04-20 14:34 ` emacs 21.2 cvs tag? Stefan Monnier
2004-04-20 22:32   ` Thien-Thi Nguyen
2004-04-21 10:03     ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87isfl54hn.fsf_-_@emacswiki.org \
    --to=alex@emacswiki.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).