noch DOCUMENT-Tests
[cxml-stp.git] / classes.lisp
blob46ab22a494b69c72460cf2b575db74812474ca6e
1 ;;; -*- show-trailing-whitespace: t; indent-tabs: nil -*-
3 ;;; Copyright (c) 2007 David Lichteblau. All rights reserved.
5 ;;; Redistribution and use in source and binary forms, with or without
6 ;;; modification, are permitted provided that the following conditions
7 ;;; are met:
8 ;;;
9 ;;; * Redistributions of source code must retain the above copyright
10 ;;; notice, this list of conditions and the following disclaimer.
11 ;;;
12 ;;; * Redistributions in binary form must reproduce the above
13 ;;; copyright notice, this list of conditions and the following
14 ;;; disclaimer in the documentation and/or other materials
15 ;;; provided with the distribution.
16 ;;;
17 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
18 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 (in-package :cxml-stp-impl)
31 #+sbcl
32 (declaim (optimize (debug 2)))
34 (defclass named-node-mixin ()
35 ((local-name :reader local-name :accessor %local-name)
36 (prefix :initform nil
37 :reader namespace-prefix
38 :accessor %namespace-prefix)
39 (namespace-uri :initform nil
40 :reader namespace-uri
41 :accessor %namespace-uri)))
43 (defclass attribute (leaf-node named-node-mixin)
44 ((value :accessor value))
45 (:documentation
46 "@short{Instances of this class represent attributes of an @class{element},
47 excluding namespace declarations.}
49 The @fun{parent} of an attribute is always an @class{element} or nil,
50 but the attribute is not a child of that element.
52 @see-slot{local-name}
53 @see-slot{namespace-prefix}
54 @see-slot{namespace-uri}
55 @see-slot{qualified-name}
56 @see-slot{value}
57 @see{list-attributes}
58 @see-constructor{make-attribute}"))
60 (defclass comment (leaf-node)
61 ((data :initarg :data :accessor data))
62 (:documentation
63 "Instances of this class represent XML comments.
64 @see-slot{data}
65 @see-constructor{make-comment}"))
67 (defclass cxml-stp:document-type (leaf-node)
68 ((root-element-name :accessor root-element-name)
69 (system-id :initform nil :accessor system-id)
70 (public-id :initform nil :accessor public-id)
71 (internal-subset :initform nil :accessor internal-subset))
72 (:documentation
73 "@short{Instances of this class represent the DOCTYPE declaration at the
74 beginning of a document.}
76 The document type is an optional child of a @class{document}. At most
77 one document type is allowed, and it must precede the document element.
79 Since STP checks well-formedness only, not validity, the document type
80 only declares what DTD the document claims to be conforming to, but
81 does not guarantee that it actually does.
83 @see-constructor{make-document-type}
84 @see-slot{root-element-name}
85 @see-slot{system-id}
86 @see-slot{public-id}
87 @see-slot{internal-subset}"))
88 (setf (find-class 'document-type) (find-class 'cxml-stp:document-type))
90 (defclass cxml-stp:document (parent-node) ()
91 (:documentation
92 "@short{Instances of this class represent an entire XML document.}
94 A document may have at most one document-type, and must have exactly one
95 element as a child (in this order).
97 It may also have comments and processing-instructions anywhere.
99 @see-constructor{make-document}
100 @see-slot{document-element}
101 @see-slot{document-type}"))
102 (setf (find-class 'document) (find-class 'cxml-stp:document))
104 (defclass element (parent-node named-node-mixin)
105 ((attributes :initform nil :accessor %attributes)
106 (namespaces :initform nil :accessor %namespaces))
107 (:documentation
108 "@short{Instances of this class represent XML elements with their attributes
109 and namespaces.}
111 See @class{node} for functions to query the list of children.
113 See @class{parent-node} for functions to add or remove children.
115 @see-slot{local-name}
116 @see-slot{namespace-prefix}
117 @see-slot{namespace-uri}
118 @see-slot{qualified-name}
119 @see{add-attribute}
120 @see{remove-attribute}
121 @see{find-attribute-named}
122 @see{find-attribute-if}
123 @see{with-attributes}
124 @see{list-attributes}
125 @see{map-attributes}
126 @see{attribute-value}
127 @see{find-namespace}
128 @see{find-attribute-namespace}
129 @see{find-local-namespace}
130 @see{find-extra-namespace}
131 @see{add-extra-namespace}
132 @see{remove-extra-namespace}
133 @see{map-extra-namespaces}
134 @see-constructor{make-element}"))
136 (defclass leaf-node (node) ())
138 (defclass node ()
139 ((parent :initform nil :reader parent :writer (setf %parent)))
140 (:documentation
141 "@short{The superclass of all nodes.}
143 Although only @class{document} and @class{element} allow children,
144 read-only functions accessing the list of children are available for
145 all nodes and always return zero children for other classes.
147 @see-slot{parent}
148 @see-slot{base-uri}
149 @see{document}
150 @see{root}
151 @see{detach}
152 @see{copy}
153 @see{serialize}
154 @see{map-children}
155 @see{do-children}
156 @see{list-children}
157 @see{first-child}
158 @see{last-child}
159 @see{nth-child}
160 @see{previous-sibling}
161 @see{next-sibling}
162 @see{count-children}
163 @see{find-child}
164 @see{child-position}
165 @see{count-children-if}
166 @see{find-child-if}
167 @see{child-position-if}
168 @see{filter-children}
169 @see{map-recursively}
170 @see{do-recursively}
171 @see{find-recursively}
172 @see{filter-recursively}"))
174 (defclass parent-node (node)
175 ((%base-uri :initform nil)
176 (%children :initform nil :accessor %children))
177 (:documentation
178 "@short{Instances of this class can have children.}
180 See @class{node} for functions to query the list of children without
181 changing it.
183 @see{prepend-child}
184 @see{append-child}
185 @see{delete-nth-child}
186 @see{delete-child}
187 @see{insert-child-before}
188 @see{insert-child-after}
189 @see{replace-child}
190 @see{insert-child}
191 @see{delete-child-if}
192 @see{replace-children}"))
194 (defclass processing-instruction (leaf-node)
195 ((target :initarg :target :accessor target)
196 (data :initarg :data :accessor data))
197 (:documentation
198 "Instances of this class represent processing instructions.
199 @see-slot{target}
200 @see-slot{data}
201 @see-constructor{make-processing-instruction}"))
203 (defclass text (leaf-node)
204 ((data :initarg :data :accessor data))
205 (:documentation
206 "Instances of this class represent text nodes.
207 @see-slot{data}
208 @see-constructor{make-text}"))