| 1 | This is a short tutorial on using dtd-mode when creating new
|
|---|
| 2 | declarations and working with existing declarations in DTD files.
|
|---|
| 3 |
|
|---|
| 4 | This tutorial uses the following conventions:
|
|---|
| 5 |
|
|---|
| 6 | Control keys are written with the prefix "C-".
|
|---|
| 7 |
|
|---|
| 8 | Meta key combinations are written with the prefix "M-".
|
|---|
| 9 |
|
|---|
| 10 | The return key is written as "RET".
|
|---|
| 11 |
|
|---|
| 12 | The space character is written as "SPACE".
|
|---|
| 13 |
|
|---|
| 14 | Sequences of keys are written with space between them, and the
|
|---|
| 15 | space character should not be typed.
|
|---|
| 16 |
|
|---|
| 17 | Input terminated by RET is generally written with "Enter...".
|
|---|
| 18 |
|
|---|
| 19 | Input that does not need RET is generally written with "Type...".
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | * CREATING A NEW DTD
|
|---|
| 23 |
|
|---|
| 24 | You are going to create the following DTD file:
|
|---|
| 25 |
|
|---|
| 26 | ------------------------------------------------------------
|
|---|
| 27 | <?xml version="1.0" encoding="utf-8"?>
|
|---|
| 28 | <!-- ============================================================= -->
|
|---|
| 29 | <!-- dtd-mode tutorial DTD -->
|
|---|
| 30 | <!-- ============================================================= -->
|
|---|
| 31 |
|
|---|
| 32 | <!-- Paragraph Content -->
|
|---|
| 33 | <!-- Content allowed inside paragraphs -->
|
|---|
| 34 | <!ENTITY % paracon "#PCDATA | list" >
|
|---|
| 35 |
|
|---|
| 36 | <!-- Book -->
|
|---|
| 37 | <!ELEMENT book (para | list)+ >
|
|---|
| 38 |
|
|---|
| 39 | <!-- Paragraph -->
|
|---|
| 40 | <!ELEMENT para (%paracon;)* >
|
|---|
| 41 |
|
|---|
| 42 | <!-- List -->
|
|---|
| 43 | <!ELEMENT list (item+) >
|
|---|
| 44 | <!-- type Specifies the formatting applied to the list
|
|---|
| 45 | items
|
|---|
| 46 | id Unique identifier -->
|
|---|
| 47 | <!ATTLIST list
|
|---|
| 48 | type (ordered | unordered) #REQUIRED
|
|---|
| 49 | id ID #IMPLIED >
|
|---|
| 50 |
|
|---|
| 51 | <!-- List Item -->
|
|---|
| 52 | <!ELEMENT item (para | list)+ >
|
|---|
| 53 |
|
|---|
| 54 | <!-- End of dtd-mode tutorial DTD -->
|
|---|
| 55 | ------------------------------------------------------------
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 | 1. Find the file "tutorial.dtd":
|
|---|
| 59 |
|
|---|
| 60 | 1.1 Enter "C-x C-f tutorial.dtd".
|
|---|
| 61 |
|
|---|
| 62 | Since it doesn't exist, Emacs will create it.
|
|---|
| 63 |
|
|---|
| 64 | 2. Enter the XML declaration:
|
|---|
| 65 |
|
|---|
| 66 | <?xml version="1.0" encoding="utf-8"?>
|
|---|
| 67 |
|
|---|
| 68 | 3. Enter the comment "dtd-mode tutorial DTD":
|
|---|
| 69 |
|
|---|
| 70 | 3.1 Type "C-u C-c C-c".
|
|---|
| 71 |
|
|---|
| 72 | 3.2 At the prompt, enter "dtd-mode tutorial DTD".
|
|---|
| 73 |
|
|---|
| 74 | 4. Insert a blank line, then enter the internal parameter entity
|
|---|
| 75 | declaration:
|
|---|
| 76 |
|
|---|
| 77 | 4.1 Type "C-c C-%".
|
|---|
| 78 |
|
|---|
| 79 | 4.2 At the first prompt, enter "paracon".
|
|---|
| 80 |
|
|---|
| 81 | 4.3 At the successive prompts, enter "Paragraph Content", "Content
|
|---|
| 82 | allowed inside paragraphs", and "#PCDATA | list".
|
|---|
| 83 |
|
|---|
| 84 | 5. Insert a blank line, then enter the <book> element type
|
|---|
| 85 | declaration:
|
|---|
| 86 |
|
|---|
| 87 | 5.1 Type "C-c C-e".
|
|---|
| 88 |
|
|---|
| 89 | 5.2 At the first prompt, enter "book".
|
|---|
| 90 |
|
|---|
| 91 | 5.3 At the successive prompts, enter (or change to make) "Book", ""
|
|---|
| 92 | (since we're not bothering with a comment), and "(para |
|
|---|
| 93 | list)+".
|
|---|
| 94 |
|
|---|
| 95 | 6. Create a TAGS file:
|
|---|
| 96 |
|
|---|
| 97 | 6.1 Type "C-x C-s" to save "tutorial.dtd".
|
|---|
| 98 |
|
|---|
| 99 | 6.2 Enter "M-x dtd-etags".
|
|---|
| 100 |
|
|---|
| 101 | 6.3 At the prompt, enter "tutorial.dtd".
|
|---|
| 102 |
|
|---|
| 103 | 7. Insert a blank line then enter the <para> element type declaration:
|
|---|
| 104 |
|
|---|
| 105 | 7.1 Type "C-c C-e".
|
|---|
| 106 |
|
|---|
| 107 | 7.2 At the prompt, accept "para" as the default.
|
|---|
| 108 |
|
|---|
| 109 | Note that you can scroll through this history list (and all
|
|---|
| 110 | other minibuffer history lists) with "M-p" and "M-n".
|
|---|
| 111 |
|
|---|
| 112 | 7.3 At the next two prompts, enter (or change to make) "Paragraph"
|
|---|
| 113 | and "".
|
|---|
| 114 |
|
|---|
| 115 | 7.4 At the content specification prompt, type "(%", then type
|
|---|
| 116 | "M-TAB" if using Emacs 19.34 ("ESC TAB" if using NTEmacs,
|
|---|
| 117 | "C-u M-TAB" if using Emacs 20.3, "C-u ESC TAB" if using
|
|---|
| 118 | NTEmacs 20.3, or "C-M-i" if "M-TAB" is preempted by the
|
|---|
| 119 | operating system).
|
|---|
| 120 |
|
|---|
| 121 | Emacs will complete the parameter entity name using the
|
|---|
| 122 | information from the TAGS file created with `dtd-etags'.
|
|---|
| 123 |
|
|---|
| 124 | 7.5 Enter ")*" to complete the content specification.
|
|---|
| 125 |
|
|---|
| 126 | 8. Insert a blank line, then enter the <list> element type
|
|---|
| 127 | declaration:
|
|---|
| 128 |
|
|---|
| 129 | 8.1 Type "C-c C-e".
|
|---|
| 130 |
|
|---|
| 131 | 8.2 At the prompt, accept "list" as the default.
|
|---|
| 132 |
|
|---|
| 133 | "list" is now the default since "para" was removed from the
|
|---|
| 134 | history list when the <para> element type was declared.
|
|---|
| 135 |
|
|---|
| 136 | 8.3 At the successive prompts, enter "List", "", and "(item+)".
|
|---|
| 137 |
|
|---|
| 138 | 9. Enter the attribute list declaration for <list>:
|
|---|
| 139 |
|
|---|
| 140 | 9.1 Type "C-c C-a".
|
|---|
| 141 |
|
|---|
| 142 | 9.2 At the prompt, accept "list" as the element type name.
|
|---|
| 143 |
|
|---|
| 144 | 9.3 At successive prompts, enter "type", "Specifies the formatting
|
|---|
| 145 | applied to the list items", and "(ordered | unordered)".
|
|---|
| 146 |
|
|---|
| 147 | 9.4 At the prompt for the default, type "M-p M-p" to select
|
|---|
| 148 | "#REQUIRED".
|
|---|
| 149 |
|
|---|
| 150 | 9.5 Type "C-c C-a".
|
|---|
| 151 |
|
|---|
| 152 | 9.6 At successive prompts, enter "id" and "Unique identifier".
|
|---|
| 153 |
|
|---|
| 154 | 9.7 At the prompt for the attribute type, repeatedly type "M-p"
|
|---|
| 155 | until the prompt value is "ID".
|
|---|
| 156 |
|
|---|
| 157 | "ID" is present because the attribute type minibuffer was
|
|---|
| 158 | initialised with the attribute types allowed in XML.
|
|---|
| 159 |
|
|---|
| 160 | 9.8 At the default prompt, repeatedly type "M-p" until the prompt
|
|---|
| 161 | value is "#IMPLIED".
|
|---|
| 162 |
|
|---|
| 163 | Note how the minibuffer history list keeps the most recently
|
|---|
| 164 | used value at the head of the list.
|
|---|
| 165 |
|
|---|
| 166 | When the second attribute is entered, its comment is merged
|
|---|
| 167 | with that of the first attribute, and the ">" at the end of the
|
|---|
| 168 | attribute list declaration is moved to after the declaration
|
|---|
| 169 | for the second attribute. If point (i.e. the cursor position)
|
|---|
| 170 | had been before the declaration for the first attribute, the
|
|---|
| 171 | second attribute would have been inserted before the first.
|
|---|
| 172 |
|
|---|
| 173 | 10. Insert a blank line, then enter the declaration for <item>.
|
|---|
| 174 |
|
|---|
| 175 | Note that "item" is the default in the "Element tag" minibuffer
|
|---|
| 176 | history list and, since the <item> content model is that same as
|
|---|
| 177 | that for <book>, the content specification can be recalled from
|
|---|
| 178 | the minibuffer history list for content specifications.
|
|---|
| 179 |
|
|---|
| 180 | 11. Insert a blank line, then enter the closing comment:
|
|---|
| 181 |
|
|---|
| 182 | 11.1 Type "C-c C-c".
|
|---|
| 183 |
|
|---|
| 184 | 11.2 Enter "End of dtd-mode tutorial DTD".
|
|---|
| 185 |
|
|---|
| 186 | 12. Enter "C-x C-s" to save the file.
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 | * WORKING WITH AN EXISTING DTD
|
|---|
| 190 |
|
|---|
| 191 | 1. Open or create tutorial.dtd.
|
|---|
| 192 |
|
|---|
| 193 | 1.1 Enter "C-x C-f tutorial.dtd".
|
|---|
| 194 |
|
|---|
| 195 | 2. Update the TAGS file:
|
|---|
| 196 |
|
|---|
| 197 | 2.1 Enter "M-x dtd-etags".
|
|---|
| 198 |
|
|---|
| 199 | 2.2 If necessary, enter "tutorial.dtd".
|
|---|
| 200 |
|
|---|
| 201 | 3. Find the declaration for <para>:
|
|---|
| 202 |
|
|---|
| 203 | 3.1 Type "M-.".
|
|---|
| 204 |
|
|---|
| 205 | 3.2 At the prompt, enter "para".
|
|---|
| 206 |
|
|---|
| 207 | Point moves to the first token in the content model for <para>.
|
|---|
| 208 |
|
|---|
| 209 | 4. Find the declaration for %paracon; in another window:
|
|---|
| 210 |
|
|---|
| 211 | 4.1 Type "C-x 4 .".
|
|---|
| 212 |
|
|---|
| 213 | 4.2 Enter "RET" to accept the default.
|
|---|
| 214 |
|
|---|
| 215 | Point moves to the first token in the replacement text for
|
|---|
| 216 | %paracon;.
|
|---|
| 217 |
|
|---|
| 218 | 5. Find the declarations for <list>:
|
|---|
| 219 |
|
|---|
| 220 | 5.1 Type "M-f M-f" to move point to the "list" text.
|
|---|
| 221 |
|
|---|
| 222 | 5.2 Type "M-." and accept the default.
|
|---|
| 223 |
|
|---|
| 224 | Point moves to the first token in the <list> content
|
|---|
| 225 | specification.
|
|---|
| 226 |
|
|---|
| 227 | 5.3 Type "M-0 M-.".
|
|---|
| 228 |
|
|---|
| 229 | Emacs uses the same tag, moves to the next occurrence of the
|
|---|
| 230 | <list> element type name, and leaves point at the start of the
|
|---|
| 231 | first attribute name.
|
|---|
| 232 |
|
|---|
| 233 | 5.4 Type "M-- M-.".
|
|---|
| 234 |
|
|---|
| 235 | Point moves back to the previous use of the <list> element type
|
|---|
| 236 | name.
|
|---|
| 237 |
|
|---|
| 238 | 6. Find all occurrences of "list":
|
|---|
| 239 |
|
|---|
| 240 | 6.1 Enter "M-x dtd-grep".
|
|---|
| 241 |
|
|---|
| 242 | 6.2 Enter "list".
|
|---|
| 243 |
|
|---|
| 244 | 6.3 Accept the default file specification, since it is the same as
|
|---|
| 245 | was used with `dtd-etags'.
|
|---|
| 246 |
|
|---|
| 247 | The other window shows all occurrences of "list" in the
|
|---|
| 248 | tutorial.dtd.
|
|---|
| 249 |
|
|---|
| 250 | 6.4 Type "C-x `". (That's the 'backtick' or 'reverse single
|
|---|
| 251 | quote'.)
|
|---|
| 252 |
|
|---|
| 253 | Point moves to the first occurrence of "list", and the *grep*
|
|---|
| 254 | buffer scrolls to place the corresponding line at the top of
|
|---|
| 255 | the window.
|
|---|
| 256 |
|
|---|
| 257 | 6.5 Move to another line in the other window (e.g. type "C-x o C-n
|
|---|
| 258 | C-n C-n") then type "RET".
|
|---|
| 259 |
|
|---|
| 260 | Point moves to that occurrence of "list" in tutorial.dtd, and
|
|---|
| 261 | the *grep* buffer scrolls to place the line at the top of the
|
|---|
| 262 | buffer.
|
|---|
| 263 |
|
|---|
| 264 | 7. Change all "paracon" to "ParaContent":
|
|---|
| 265 |
|
|---|
| 266 | 7.1 Enter "M-x tags-query-replace".
|
|---|
| 267 |
|
|---|
| 268 | 7.2 Enter "paracon" at the first prompt, and "ParaContent" at the
|
|---|
| 269 | second.
|
|---|
| 270 |
|
|---|
| 271 | 7.3 Type "SPACE SPACE" to perform the two replacements.
|
|---|
| 272 |
|
|---|
| 273 | These changes could have been done with `query-replace-regexp'
|
|---|
| 274 | since we're working with a single file, but
|
|---|
| 275 | `tags-query-replace' will also work across multiple files.
|
|---|
| 276 |
|
|---|
| 277 | Since there isn't yet a auto-fill function for declarations,
|
|---|
| 278 | the changed declarations need fixing.
|
|---|
| 279 |
|
|---|
| 280 | 7.4 Type "C-c >".
|
|---|
| 281 |
|
|---|
| 282 | The ">" ending the declaration moves to the correct column.
|
|---|
| 283 | This same function will insert a ">" if there isn't one on the
|
|---|
| 284 | line, and will insert or move "-->" if inside a comment.
|
|---|
| 285 |
|
|---|
| 286 | 7.5 Fix the other declaration manually.
|
|---|
| 287 |
|
|---|
| 288 | One day there'll be an auto-fill function...
|
|---|
| 289 |
|
|---|
| 290 | 8. Use the "Goto" menu to find the declaration for <item>:
|
|---|
| 291 |
|
|---|
| 292 | 8.1 Under the "Goto" menu, select the "item" entry.
|
|---|
| 293 |
|
|---|
| 294 | Point moves to the first token in the <item> content
|
|---|
| 295 | specification.
|
|---|
| 296 |
|
|---|
| 297 | 9. Type "C-x C-s" to save the file.
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 | -----
|
|---|
| 301 | $Id: tutorial.txt,v 1.8 2001-08-31 23:14:30-04 tkg Exp $
|
|---|
| 302 | $Name: tdtd08b1 $
|
|---|