emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

xml.el


From: Alex Schroeder
Subject: xml.el
Date: Wed, 28 Apr 2004 02:29:56 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/22.0.0 (gnu/linux)

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>address@hidden</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>address@hidden
        </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  <address@hidden>

        * 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 via email to

[Prev in Thread] Current Thread [Next in Thread]