annotate lisp/xml.el @ 30729:b81e74b4a7a6

*** empty log message ***
author Gerd Moellmann <gerd@gnu.org>
date Thu, 10 Aug 2000 09:21:43 +0000
parents 1ea701655cf8
children aa097d8d4f1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30329
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;; @(#) xml.el --- XML parser
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 2000 Free Software Foundation, Inc.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Author: Emmanuel Briot <briot@gnat.com>
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Maintainer: Emmanuel Briot <briot@gnat.com>
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; Keywords: xml
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; any later version.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; This file contains a full XML parser. It parses a file, and returns a list
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; that can be used internally by any other lisp file.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; See some example in todo.el
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;;; FILE FORMAT
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;; It does not parse the DTD, if present in the XML file, but knows how to
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; ignore it. The XML file is assumed to be well-formed. In case of error, the
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; parsing stops and the XML file is shown where the parsing stopped.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;;
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; It also knows how to ignore comments, as well as the special ?xml? tag
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; in the XML file.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;;
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;; The XML file should have the following format:
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; <node1 attr1="name1" attr2="name2" ...> value
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; <node2 attr3="name3" attr4="name4"> value2 </node2>
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; <node3 attr5="name5" attr6="name6"> value3 </node3>
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; </node1>
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;; Of course, the name of the nodes and attributes can be anything. There can
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; be any number of attributes (or none), as well as any number of children
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; below the nodes.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;;
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; There can be only top level node, but with any number of children below.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;;; LIST FORMAT
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; The functions `xml-parse-file' and `xml-parse-tag' return a list with
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; the following format:
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;;
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; xml-list ::= (node node ...)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; node ::= (tag_name attribute-list . child_node_list)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; child_node_list ::= child_node child_node ...
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;; child_node ::= node | string
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; tag_name ::= string
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; attribute_list ::= (("attribute" . "value") ("attribute" . "value") ...)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; | nil
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;; string ::= "..."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;;
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;; Since XML is case insensitive, tag_name is always converted to lower-cases.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;; tag_name is then converted to a symbol (this is not a string, so that the
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 ;; list takes less space in memory and is faster to traverse).
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;;
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; Some macros are provided to ease the parsing of this list
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 ;;; Code:
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;;*******************************************************************
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;;**
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 ;;** Macros to parse the list
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;;**
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;;*******************************************************************
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 (defmacro xml-node-name (node)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 "Return the tag associated with NODE.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 The tag is a lower-case symbol."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 (list 'car node))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 (defmacro xml-node-attributes (node)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 "Return the list of attributes of NODE.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 The list can be nil."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 (list 'nth 1 node))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 (defmacro xml-node-children (node)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 "Return the list of children of NODE.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 This is a list of nodes, and it can be nil."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 (list 'cddr node))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 (defun xml-get-children (node child-name)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 "Return the children of NODE whose tag is CHILD-NAME.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 CHILD-NAME should be a lower case symbol."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (let ((children (xml-node-children node))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 match)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 (while children
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (if (car children)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 (if (equal (xml-node-name (car children)) child-name)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 (set 'match (append match (list (car children))))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (set 'children (cdr children)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 match))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 (defun xml-get-attribute (node attribute)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 "Get from NODE the value of ATTRIBUTE.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 An empty string is returned if the attribute was not found."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (if (xml-node-attributes node)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 (let ((value (assoc attribute (xml-node-attributes node))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (if value
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 (cdr value)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 ""))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 ""))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 ;;*******************************************************************
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 ;;**
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 ;;** Creating the list
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 ;;**
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 ;;*******************************************************************
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 (defun xml-parse-file (file &optional parse-dtd)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 "Parse the well-formed XML FILE.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 Returns the top node with all its children.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 If PARSE-DTD is non-nil, the DTD is parsed rather than skipped."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (find-file file)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 (let ((xml (xml-parse-region (point-min)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (point-max)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (current-buffer)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 parse-dtd)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 (kill-buffer (current-buffer))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 xml))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (defun xml-parse-region (beg end &optional buffer parse-dtd)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 "Parse the region from BEG to END in BUFFER.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 If BUFFER is nil, it defaults to the current buffer.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 Returns the XML list for the region, or raises an error if the region
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 is not a well-formed XML file.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 If PARSE-DTD is non-nil, the DTD is parsed rather than skipped,
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 and returned as the first element of the list"
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (let (xml result dtd)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (save-excursion
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (if buffer
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (set-buffer buffer))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (goto-char beg)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (while (< (point) end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (if (search-forward "<" end t)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (progn
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (forward-char -1)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 (if (null xml)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (progn
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (set 'result (xml-parse-tag end parse-dtd))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 (cond
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 ((listp (car result))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (set 'dtd (car result))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (add-to-list 'xml (cdr result)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (t
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (add-to-list 'xml result))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 ;; translation of rule [1] of XML specifications
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (error "XML files can have only one toplevel tag.")))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 (goto-char end)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 (if parse-dtd
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (cons dtd (reverse xml))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (reverse xml)))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (defun xml-parse-tag (end &optional parse-dtd)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 "Parse the tag that is just in front of point.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 The end tag must be found before the position END in the current buffer.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 If PARSE-DTD is non-nil, the DTD of the document, if any, is parsed and
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 returned as the first element in the list.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 Returns one of:
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 - a list : the matching node
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 - nil : the point is not looking at a tag.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 - a cons cell: the first element is the DTD, the second is the node"
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (cond
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 ;; Processing instructions (like the <?xml version="1.0"?> tag at the
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 ;; beginning of a document)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 ((looking-at "<\\?")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (search-forward "?>" end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 (xml-parse-tag end))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 ;; Character data (CDATA) sections, in which no tag should be interpreted
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 ((looking-at "<!\\[CDATA\\[")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 (let ((pos (match-end 0)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 (unless (search-forward "]]>" end t)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (error "CDATA section does not end anywhere in the document"))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (buffer-substring-no-properties pos (match-beginning 0))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 ;; DTD for the document
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 ((looking-at "<!DOCTYPE")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (let (dtd)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 (if parse-dtd
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 (set 'dtd (xml-parse-dtd end))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 (xml-skip-dtd end))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 (if dtd
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (cons dtd (xml-parse-tag end))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 (xml-parse-tag end))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 ;; skip comments
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 ((looking-at "<!--")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (search-forward "-->" end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 (xml-parse-tag end))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 ;; end tag
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 ((looking-at "</")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 '())
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 ;; opening tag
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 ((looking-at "<\\([^/> \t]+\\)")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (let* ((node-name (match-string 1))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (children (list (intern (downcase node-name))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 pos)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (goto-char (match-end 1))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 ;; parses the attribute list
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (set 'children (append children (list (xml-parse-attlist end))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 ;; is this an empty element ?
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (if (looking-at "/>")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (progn
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (forward-char 2)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (append children '("")))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 ;; is this a valid start tag ?
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (if (= (char-after) ?>)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (progn
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (forward-char 1)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 (while (not (looking-at (concat "</" node-name ">")))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (cond
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 ((looking-at "</")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (error (concat
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 "XML: invalid syntax -- invalid end tag (expecting "
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 node-name
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 ")")))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 ((= (char-after) ?<)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 (set 'children (append children (list (xml-parse-tag end)))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 (t
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (set 'pos (point))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 (search-forward "<" end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 (forward-char -1)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (let ((string (buffer-substring-no-properties pos (point)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 (pos 0))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 ;; Clean up the string (no newline characters)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 ;; Not done, since as per XML specifications, the XML processor
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 ;; should always pass the whole string to the application.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 ;; (while (string-match "\\s +" string pos)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 ;; (set 'string (replace-match " " t t string))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 ;; (set 'pos (1+ (match-beginning 0))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 (set 'children (append children
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 (list (xml-substitute-special string))))))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (goto-char (match-end 0))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 (if (> (point) end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (error "XML: End tag for %s not found before end of region."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 node-name))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 children
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 )
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 ;; This was an invalid start tag
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (error "XML: Invalid attribute list")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 ))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 ))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 (defun xml-parse-attlist (end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 "Return the attribute-list that point is looking at.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 The search for attributes end at the position END in the current buffer.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 Leaves the point on the first non-blank character after the tag."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (let ((attlist '())
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 name)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (while (looking-at "\\([a-zA-Z_:][a-zA-Z0-9.-_:]*\\)[ \t\n]*=[ \t\n]*")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (set 'name (intern (downcase (match-string 1))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (goto-char (match-end 0))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 ;; Do we have a string between quotes (or double-quotes),
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 ;; or a simple word ?
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (unless (looking-at "\"\\([^\"]+\\)\"")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (unless (looking-at "'\\([^\"]+\\)'")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (error "XML: Attribute values must be given between quotes.")))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 ;; Each attribute must be unique within a given element
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 (if (assoc name attlist)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (error "XML: each attribute must be unique within an element."))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (set 'attlist (append attlist
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (list (cons name (match-string 1)))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (goto-char (match-end 0))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (if (> (point) end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 (error "XML: end of attribute list not found before end of region."))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 )
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 attlist
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 ))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 ;;*******************************************************************
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 ;;**
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 ;;** The DTD (document type declaration)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 ;;** The following functions know how to skip or parse the DTD of
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 ;;** a document
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 ;;**
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 ;;*******************************************************************
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 (defun xml-skip-dtd (end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 "Skip the DTD that point is looking at.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 The DTD must end before the position END in the current buffer.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 The point must be just before the starting tag of the DTD.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 This follows the rule [28] in the XML specifications."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 (forward-char (length "<!DOCTYPE"))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (if (looking-at "[ \t\n]*>")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 (error "XML: invalid DTD (excepting name of the document)"))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 (condition-case nil
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 (progn
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (forward-word 1) ;; name of the document
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (if (looking-at "\\[")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 (re-search-forward "\\][ \t\n]*>" end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 (search-forward ">" end)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 (error (error "XML: No end to the DTD"))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 (defun xml-parse-dtd (end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 "Parse the DTD that point is looking at.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 The DTD must end before the position END in the current buffer."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (let (dtd type element end-pos)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 (forward-char (length "<!DOCTYPE"))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (if (looking-at ">")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 (error "XML: invalid DTD (excepting name of the document)"))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 ;; Get the name of the document
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 (looking-at "\\sw+")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (set 'dtd (list 'dtd (match-string-no-properties 0)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (goto-char (match-end 0))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (skip-chars-forward " \t\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 ;; External DTDs => don't know how to handle them yet
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 (if (looking-at "SYSTEM")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 (error "XML: Don't know how to handle external DTDs."))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 (if (not (= (char-after) ?\[))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 (error "XML: Unknown declaration in the DTD."))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 ;; Parse the rest of the DTD
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 (forward-char 1)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (while (and (not (looking-at "[ \t\n]*\\]"))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 (<= (point) end))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 (cond
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 ;; Translation of rule [45] of XML specifications
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 ((looking-at
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 "[\t \n]*<!ELEMENT[ \t\n]+\\([a-zA-Z0-9.%;]+\\)[ \t\n]+\\([^>]+\\)>")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 (setq element (intern (downcase (match-string-no-properties 1)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 type (match-string-no-properties 2))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 (set 'end-pos (match-end 0))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 ;; Translation of rule [46] of XML specifications
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 (cond
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 ((string-match "^EMPTY[ \t\n]*$" type) ;; empty declaration
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 (set 'type 'empty))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 ((string-match "^ANY[ \t\n]*$" type) ;; any type of contents
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 (set 'type 'any))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 ((string-match "^(\\(.*\\))[ \t\n]*$" type) ;; children ([47])
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 (set 'type (xml-parse-elem-type (match-string-no-properties 1 type))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 ((string-match "^%[^;]+;[ \t\n]*$" type) ;; substitution
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 nil)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 (t
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (error "XML: Invalid element type in the DTD")))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 ;; rule [45]: the element declaration must be unique
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 (if (assoc element dtd)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (error "XML: elements declaration must be unique in a DTD (<%s>)."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 (symbol-name element)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 ;; Store the element in the DTD
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (set 'dtd (append dtd (list (list element type))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 (goto-char end-pos)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 )
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 (t
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (error "XML: Invalid DTD item"))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 )
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 )
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 ;; Skip the end of the DTD
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (search-forward ">" end)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 dtd
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 ))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 (defun xml-parse-elem-type (string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 "Convert a STRING for an element type into an elisp structure."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (let (elem modifier)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (if (string-match "(\\([^)]+\\))\\([+*?]?\\)" string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (progn
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (setq elem (match-string 1 string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 modifier (match-string 2 string))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 (if (string-match "|" elem)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (set 'elem (append '(choice)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 (mapcar 'xml-parse-elem-type
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 (split-string elem "|"))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 (if (string-match "," elem)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 (set 'elem (append '(seq)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 (mapcar 'xml-parse-elem-type
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 (split-string elem ","))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 )))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 (if (string-match "[ \t\n]*\\([^+*?]+\\)\\([+*?]?\\)" string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (setq elem (match-string 1 string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 modifier (match-string 2 string))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 (if (and (stringp elem)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 (string= elem "#PCDATA"))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 (set 'elem 'pcdata))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 (cond
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 ((string= modifier "+")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 (list '+ elem))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 ((string= modifier "*")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (list '* elem))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 ((string= modifier "?")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (list '? elem))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 (t
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 elem))))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 ;;*******************************************************************
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 ;;**
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 ;;** Substituting special XML sequences
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 ;;**
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 ;;*******************************************************************
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 (defun xml-substitute-special (string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 "Return STRING, after subsituting special XML sequences."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 (while (string-match "&amp;" string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (set 'string (replace-match "&" t nil string)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 (while (string-match "&lt;" string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 (set 'string (replace-match "<" t nil string)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 (while (string-match "&gt;" string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (set 'string (replace-match ">" t nil string)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447 (while (string-match "&apos;" string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (set 'string (replace-match "'" t nil string)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 (while (string-match "&quot;" string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (set 'string (replace-match "\"" t nil string)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 ;;*******************************************************************
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 ;;**
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 ;;** Printing a tree.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 ;;** This function is intended mainly for debugging purposes.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 ;;**
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 ;;*******************************************************************
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 (defun xml-debug-print (xml)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461 (while xml
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 (xml-debug-print-internal (car xml) "")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 (set 'xml (cdr xml)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 )
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 (defun xml-debug-print-internal (xml &optional indent-string)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 "Outputs the XML tree in the current buffer.
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 The first line indented with INDENT-STRING."
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 (let ((tree xml)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 attlist)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 (unless indent-string
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 (set 'indent-string ""))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 (insert indent-string "<" (symbol-name (xml-node-name tree)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 ;; output the attribute list
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 (set 'attlist (xml-node-attributes tree))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 (while attlist
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 (insert " ")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 (insert (symbol-name (caar attlist)) "=\"" (cdar attlist) "\"")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (set 'attlist (cdr attlist)))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (insert ">")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 (set 'tree (xml-node-children tree))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 ;; output the children
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 (while tree
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 (cond
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 ((listp (car tree))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (insert "\n")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 (xml-debug-print-internal (car tree) (concat indent-string " "))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 )
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 ((stringp (car tree))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 (insert (car tree))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 )
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 (t
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 (error "Invalid XML tree")))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 (set 'tree (cdr tree))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 )
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (insert "\n" indent-string
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 "</" (symbol-name (xml-node-name xml)) ">")
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 ))
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (provide 'xml)
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507
1ea701655cf8 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508 ;;; xml.el ends here