1 | /*
|
---|
2 | * Copyright 1999-2000,2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Log: AttributeList.hpp,v $
|
---|
19 | * Revision 1.5 2004/09/26 01:06:30 cargilld
|
---|
20 | * Fix documentation generation problem. Replace <pre> with <code>. Patch from James Littlejohn.
|
---|
21 | *
|
---|
22 | * Revision 1.4 2004/09/08 13:56:19 peiyongz
|
---|
23 | * Apache License Version 2.0
|
---|
24 | *
|
---|
25 | * Revision 1.3 2003/03/07 18:10:06 tng
|
---|
26 | * Return a reference instead of void for operator=
|
---|
27 | *
|
---|
28 | * Revision 1.2 2002/11/04 14:56:25 tng
|
---|
29 | * C++ Namespace Support.
|
---|
30 | *
|
---|
31 | * Revision 1.1.1.1 2002/02/01 22:22:07 peiyongz
|
---|
32 | * sane_include
|
---|
33 | *
|
---|
34 | * Revision 1.8 2000/03/02 19:54:34 roddey
|
---|
35 | * This checkin includes many changes done while waiting for the
|
---|
36 | * 1.1.0 code to be finished. I can't list them all here, but a list is
|
---|
37 | * available elsewhere.
|
---|
38 | *
|
---|
39 | * Revision 1.7 2000/02/24 20:12:54 abagchi
|
---|
40 | * Swat for removing Log from API docs
|
---|
41 | *
|
---|
42 | * Revision 1.6 2000/02/12 03:31:55 rahulj
|
---|
43 | * Removed duplicate CVS Log entries.
|
---|
44 | *
|
---|
45 | * Revision 1.5 2000/02/12 01:27:19 aruna1
|
---|
46 | * Documentation updated
|
---|
47 | *
|
---|
48 | * Revision 1.4 2000/02/09 02:12:21 abagchi
|
---|
49 | * Added getValue docs
|
---|
50 | *
|
---|
51 | * Revision 1.3 2000/02/06 07:47:57 rahulj
|
---|
52 | * Year 2K copyright swat.
|
---|
53 | *
|
---|
54 | * Revision 1.2 1999/12/15 19:58:31 roddey
|
---|
55 | * Added new convenience version of getValue() that takes a short character
|
---|
56 | * string for the attribute name.
|
---|
57 | *
|
---|
58 | * Revision 1.1.1.1 1999/11/09 01:07:43 twl
|
---|
59 | * Initial checkin
|
---|
60 | *
|
---|
61 | * Revision 1.2 1999/11/08 20:44:54 rahul
|
---|
62 | * Swat for adding in Product name and CVS comment log variable.
|
---|
63 | *
|
---|
64 | */
|
---|
65 |
|
---|
66 | #ifndef ATTRIBUTELIST_HPP
|
---|
67 | #define ATTRIBUTELIST_HPP
|
---|
68 |
|
---|
69 | #include <xercesc/util/XercesDefs.hpp>
|
---|
70 |
|
---|
71 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Interface for an element's attribute specifications.
|
---|
75 | *
|
---|
76 | * The SAX parser implements this interface and passes an instance
|
---|
77 | * to the SAX application as the second argument of each startElement
|
---|
78 | * event.
|
---|
79 | *
|
---|
80 | * The instance provided will return valid results only during the
|
---|
81 | * scope of the startElement invocation (to save it for future
|
---|
82 | * use, the application must make a copy: the AttributeListImpl
|
---|
83 | * helper class provides a convenient constructor for doing so).
|
---|
84 | *
|
---|
85 | * An AttributeList includes only attributes that have been
|
---|
86 | * specified or defaulted: #IMPLIED attributes will not be included.
|
---|
87 | *
|
---|
88 | * There are two ways for the SAX application to obtain information
|
---|
89 | * from the AttributeList. First, it can iterate through the entire
|
---|
90 | * list:
|
---|
91 | *
|
---|
92 | * <code>
|
---|
93 | * public void startElement (String name, AttributeList atts) {<br>
|
---|
94 | * for (int i = 0; i < atts.getLength(); i++) {<br>
|
---|
95 | * String name = atts.getName(i);<br>
|
---|
96 | * String type = atts.getType(i);<br>
|
---|
97 | * String value = atts.getValue(i);<br>
|
---|
98 | * [...]<br>
|
---|
99 | * }<br>
|
---|
100 | * }
|
---|
101 | * </code>
|
---|
102 | *
|
---|
103 | * (Note that the result of getLength() will be zero if there
|
---|
104 | * are no attributes.)
|
---|
105 | *
|
---|
106 | * As an alternative, the application can request the value or
|
---|
107 | * type of specific attributes:
|
---|
108 | *
|
---|
109 | * <code>
|
---|
110 | * public void startElement (String name, AttributeList atts) {<br>
|
---|
111 | * String identifier = atts.getValue("id");<br>
|
---|
112 | * String label = atts.getValue("label");<br>
|
---|
113 | * [...]<br>
|
---|
114 | * }
|
---|
115 | * </code>
|
---|
116 | *
|
---|
117 | * The AttributeListImpl helper class provides a convenience
|
---|
118 | * implementation for use by parser or application writers.
|
---|
119 | *
|
---|
120 | * @see DocumentHandler#startElement
|
---|
121 | * @see AttributeListImpl#AttributeListImpl
|
---|
122 | */
|
---|
123 |
|
---|
124 | class SAX_EXPORT AttributeList
|
---|
125 | {
|
---|
126 | public:
|
---|
127 | // -----------------------------------------------------------------------
|
---|
128 | // Constructors and Destructor
|
---|
129 | // -----------------------------------------------------------------------
|
---|
130 | /** @name Constructors and Destructor */
|
---|
131 | //@{
|
---|
132 | /** Default constructor */
|
---|
133 | AttributeList()
|
---|
134 | {
|
---|
135 | }
|
---|
136 |
|
---|
137 | /** Destructor */
|
---|
138 | virtual ~AttributeList()
|
---|
139 | {
|
---|
140 | }
|
---|
141 | //@}
|
---|
142 |
|
---|
143 | /** @name The virtual attribute list interface */
|
---|
144 | //@{
|
---|
145 | /**
|
---|
146 | * Return the number of attributes in this list.
|
---|
147 | *
|
---|
148 | * The SAX parser may provide attributes in any
|
---|
149 | * arbitrary order, regardless of the order in which they were
|
---|
150 | * declared or specified. The number of attributes may be
|
---|
151 | * zero.
|
---|
152 | *
|
---|
153 | * @return The number of attributes in the list.
|
---|
154 | */
|
---|
155 | virtual unsigned int getLength() const = 0;
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Return the name of an attribute in this list (by position).
|
---|
159 | *
|
---|
160 | * The names must be unique: the SAX parser shall not include the
|
---|
161 | * same attribute twice. Attributes without values (those declared
|
---|
162 | * #IMPLIED without a value specified in the start tag) will be
|
---|
163 | * omitted from the list.
|
---|
164 | *
|
---|
165 | * If the attribute name has a namespace prefix, the prefix
|
---|
166 | * will still be attached.
|
---|
167 | *
|
---|
168 | * @param index The index of the attribute in the list (starting at 0).
|
---|
169 | * @return The name of the indexed attribute, or null
|
---|
170 | * if the index is out of range.
|
---|
171 | * @see #getLength
|
---|
172 | */
|
---|
173 | virtual const XMLCh* getName(const unsigned int index) const = 0;
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * Return the type of an attribute in the list (by position).
|
---|
177 | *
|
---|
178 | * The attribute type is one of the strings "CDATA", "ID",
|
---|
179 | * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
|
---|
180 | * or "NOTATION" (always in upper case).
|
---|
181 | *
|
---|
182 | * If the parser has not read a declaration for the attribute,
|
---|
183 | * or if the parser does not report attribute types, then it must
|
---|
184 | * return the value "CDATA" as stated in the XML 1.0 Recommentation
|
---|
185 | * (clause 3.3.3, "Attribute-Value Normalization").
|
---|
186 | *
|
---|
187 | * For an enumerated attribute that is not a notation, the
|
---|
188 | * parser will report the type as "NMTOKEN".
|
---|
189 | *
|
---|
190 | * @param index The index of the attribute in the list (starting at 0).
|
---|
191 | * @return The attribute type as a string, or
|
---|
192 | * null if the index is out of range.
|
---|
193 | * @see #getLength
|
---|
194 | * @see #getType(String)
|
---|
195 | */
|
---|
196 | virtual const XMLCh* getType(const unsigned int index) const = 0;
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Return the value of an attribute in the list (by position).
|
---|
200 | *
|
---|
201 | * If the attribute value is a list of tokens (IDREFS,
|
---|
202 | * ENTITIES, or NMTOKENS), the tokens will be concatenated
|
---|
203 | * into a single string separated by whitespace.
|
---|
204 | *
|
---|
205 | * @param index The index of the attribute in the list (starting at 0).
|
---|
206 | * @return The attribute value as a string, or
|
---|
207 | * null if the index is out of range.
|
---|
208 | * @see #getLength
|
---|
209 | * @see #getValue(XMLCh*)
|
---|
210 | * @see #getValue(char *)
|
---|
211 | */
|
---|
212 | virtual const XMLCh* getValue(const unsigned int index) const = 0;
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Return the type of an attribute in the list (by name).
|
---|
216 | *
|
---|
217 | * The return value is the same as the return value for
|
---|
218 | * getType(int).
|
---|
219 | *
|
---|
220 | * If the attribute name has a namespace prefix in the document,
|
---|
221 | * the application must include the prefix here.
|
---|
222 | *
|
---|
223 | * @param name The name of the attribute.
|
---|
224 | * @return The attribute type as a string, or null if no
|
---|
225 | * such attribute exists.
|
---|
226 | * @see #getType(int)
|
---|
227 | */
|
---|
228 | virtual const XMLCh* getType(const XMLCh* const name) const = 0;
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Return the value of an attribute in the list (by name).
|
---|
232 | *
|
---|
233 | * The return value is the same as the return value for
|
---|
234 | * getValue(int).
|
---|
235 | *
|
---|
236 | * If the attribute name has a namespace prefix in the document,
|
---|
237 | * the application must include the prefix here.
|
---|
238 | *
|
---|
239 | * @param name The name of the attribute in the list.
|
---|
240 | * @return The attribute value as a string, or null if
|
---|
241 | * no such attribute exists.
|
---|
242 | * @see #getValue(int)
|
---|
243 | * @see #getValue(char *)
|
---|
244 | */
|
---|
245 | virtual const XMLCh* getValue(const XMLCh* const name) const = 0;
|
---|
246 |
|
---|
247 | /**
|
---|
248 | * Return the value of an attribute in the list (by name).
|
---|
249 | *
|
---|
250 | * The return value is the same as the return value for
|
---|
251 | * getValue(int).
|
---|
252 | *
|
---|
253 | * If the attribute name has a namespace prefix in the document,
|
---|
254 | * the application must include the prefix here.
|
---|
255 | *
|
---|
256 | * @param name The name of the attribute in the list.
|
---|
257 | * @return The attribute value as a string, or null if
|
---|
258 | * no such attribute exists.
|
---|
259 | * @see #getValue(int)
|
---|
260 | * @see #getValue(XMLCh*)
|
---|
261 | */
|
---|
262 | virtual const XMLCh* getValue(const char* const name) const = 0;
|
---|
263 | //@}
|
---|
264 |
|
---|
265 | private :
|
---|
266 | /* Constructors and operators */
|
---|
267 | /* Copy constructor */
|
---|
268 | AttributeList(const AttributeList&);
|
---|
269 | /* Assignment operator */
|
---|
270 | AttributeList& operator=(const AttributeList&);
|
---|
271 |
|
---|
272 | };
|
---|
273 |
|
---|
274 | XERCES_CPP_NAMESPACE_END
|
---|
275 |
|
---|
276 | #endif
|
---|