1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: AttributeList.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #ifndef ATTRIBUTELIST_HPP |
---|
23 | #define ATTRIBUTELIST_HPP |
---|
24 | |
---|
25 | #include <xercesc/util/XercesDefs.hpp> |
---|
26 | |
---|
27 | XERCES_CPP_NAMESPACE_BEGIN |
---|
28 | |
---|
29 | /** |
---|
30 | * Interface for an element's attribute specifications. |
---|
31 | * |
---|
32 | * The SAX parser implements this interface and passes an instance |
---|
33 | * to the SAX application as the second argument of each startElement |
---|
34 | * event. |
---|
35 | * |
---|
36 | * The instance provided will return valid results only during the |
---|
37 | * scope of the startElement invocation (to save it for future |
---|
38 | * use, the application must make a copy: the AttributeListImpl |
---|
39 | * helper class provides a convenient constructor for doing so). |
---|
40 | * |
---|
41 | * An AttributeList includes only attributes that have been |
---|
42 | * specified or defaulted: #IMPLIED attributes will not be included. |
---|
43 | * |
---|
44 | * There are two ways for the SAX application to obtain information |
---|
45 | * from the AttributeList. First, it can iterate through the entire |
---|
46 | * list: |
---|
47 | * |
---|
48 | * <code> |
---|
49 | * public void startElement (String name, AttributeList atts) {<br> |
---|
50 | * for (int i = 0; i < atts.getLength(); i++) {<br> |
---|
51 | * String name = atts.getName(i);<br> |
---|
52 | * String type = atts.getType(i);<br> |
---|
53 | * String value = atts.getValue(i);<br> |
---|
54 | * [...]<br> |
---|
55 | * }<br> |
---|
56 | * } |
---|
57 | * </code> |
---|
58 | * |
---|
59 | * (Note that the result of getLength() will be zero if there |
---|
60 | * are no attributes.) |
---|
61 | * |
---|
62 | * As an alternative, the application can request the value or |
---|
63 | * type of specific attributes: |
---|
64 | * |
---|
65 | * <code> |
---|
66 | * public void startElement (String name, AttributeList atts) {<br> |
---|
67 | * String identifier = atts.getValue("id");<br> |
---|
68 | * String label = atts.getValue("label");<br> |
---|
69 | * [...]<br> |
---|
70 | * } |
---|
71 | * </code> |
---|
72 | * |
---|
73 | * The AttributeListImpl helper class provides a convenience |
---|
74 | * implementation for use by parser or application writers. |
---|
75 | * |
---|
76 | * @see DocumentHandler#startElement |
---|
77 | * @see AttributeListImpl#AttributeListImpl |
---|
78 | */ |
---|
79 | |
---|
80 | class SAX_EXPORT AttributeList |
---|
81 | { |
---|
82 | public: |
---|
83 | // ----------------------------------------------------------------------- |
---|
84 | // Constructors and Destructor |
---|
85 | // ----------------------------------------------------------------------- |
---|
86 | /** @name Constructors and Destructor */ |
---|
87 | //@{ |
---|
88 | /** Default constructor */ |
---|
89 | AttributeList() |
---|
90 | { |
---|
91 | } |
---|
92 | |
---|
93 | /** Destructor */ |
---|
94 | virtual ~AttributeList() |
---|
95 | { |
---|
96 | } |
---|
97 | //@} |
---|
98 | |
---|
99 | /** @name The virtual attribute list interface */ |
---|
100 | //@{ |
---|
101 | /** |
---|
102 | * Return the number of attributes in this list. |
---|
103 | * |
---|
104 | * The SAX parser may provide attributes in any |
---|
105 | * arbitrary order, regardless of the order in which they were |
---|
106 | * declared or specified. The number of attributes may be |
---|
107 | * zero. |
---|
108 | * |
---|
109 | * @return The number of attributes in the list. |
---|
110 | */ |
---|
111 | virtual unsigned int getLength() const = 0; |
---|
112 | |
---|
113 | /** |
---|
114 | * Return the name of an attribute in this list (by position). |
---|
115 | * |
---|
116 | * The names must be unique: the SAX parser shall not include the |
---|
117 | * same attribute twice. Attributes without values (those declared |
---|
118 | * #IMPLIED without a value specified in the start tag) will be |
---|
119 | * omitted from the list. |
---|
120 | * |
---|
121 | * If the attribute name has a namespace prefix, the prefix |
---|
122 | * will still be attached. |
---|
123 | * |
---|
124 | * @param index The index of the attribute in the list (starting at 0). |
---|
125 | * @return The name of the indexed attribute, or null |
---|
126 | * if the index is out of range. |
---|
127 | * @see #getLength |
---|
128 | */ |
---|
129 | virtual const XMLCh* getName(const unsigned int index) const = 0; |
---|
130 | |
---|
131 | /** |
---|
132 | * Return the type of an attribute in the list (by position). |
---|
133 | * |
---|
134 | * The attribute type is one of the strings "CDATA", "ID", |
---|
135 | * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", |
---|
136 | * or "NOTATION" (always in upper case). |
---|
137 | * |
---|
138 | * If the parser has not read a declaration for the attribute, |
---|
139 | * or if the parser does not report attribute types, then it must |
---|
140 | * return the value "CDATA" as stated in the XML 1.0 Recommentation |
---|
141 | * (clause 3.3.3, "Attribute-Value Normalization"). |
---|
142 | * |
---|
143 | * For an enumerated attribute that is not a notation, the |
---|
144 | * parser will report the type as "NMTOKEN". |
---|
145 | * |
---|
146 | * @param index The index of the attribute in the list (starting at 0). |
---|
147 | * @return The attribute type as a string, or |
---|
148 | * null if the index is out of range. |
---|
149 | * @see #getLength |
---|
150 | * @see #getType(String) |
---|
151 | */ |
---|
152 | virtual const XMLCh* getType(const unsigned int index) const = 0; |
---|
153 | |
---|
154 | /** |
---|
155 | * Return the value of an attribute in the list (by position). |
---|
156 | * |
---|
157 | * If the attribute value is a list of tokens (IDREFS, |
---|
158 | * ENTITIES, or NMTOKENS), the tokens will be concatenated |
---|
159 | * into a single string separated by whitespace. |
---|
160 | * |
---|
161 | * @param index The index of the attribute in the list (starting at 0). |
---|
162 | * @return The attribute value as a string, or |
---|
163 | * null if the index is out of range. |
---|
164 | * @see #getLength |
---|
165 | * @see #getValue(XMLCh*) |
---|
166 | * @see #getValue(char *) |
---|
167 | */ |
---|
168 | virtual const XMLCh* getValue(const unsigned int index) const = 0; |
---|
169 | |
---|
170 | /** |
---|
171 | * Return the type of an attribute in the list (by name). |
---|
172 | * |
---|
173 | * The return value is the same as the return value for |
---|
174 | * getType(int). |
---|
175 | * |
---|
176 | * If the attribute name has a namespace prefix in the document, |
---|
177 | * the application must include the prefix here. |
---|
178 | * |
---|
179 | * @param name The name of the attribute. |
---|
180 | * @return The attribute type as a string, or null if no |
---|
181 | * such attribute exists. |
---|
182 | * @see #getType(int) |
---|
183 | */ |
---|
184 | virtual const XMLCh* getType(const XMLCh* const name) const = 0; |
---|
185 | |
---|
186 | /** |
---|
187 | * Return the value of an attribute in the list (by name). |
---|
188 | * |
---|
189 | * The return value is the same as the return value for |
---|
190 | * getValue(int). |
---|
191 | * |
---|
192 | * If the attribute name has a namespace prefix in the document, |
---|
193 | * the application must include the prefix here. |
---|
194 | * |
---|
195 | * @param name The name of the attribute in the list. |
---|
196 | * @return The attribute value as a string, or null if |
---|
197 | * no such attribute exists. |
---|
198 | * @see #getValue(int) |
---|
199 | * @see #getValue(char *) |
---|
200 | */ |
---|
201 | virtual const XMLCh* getValue(const XMLCh* const name) const = 0; |
---|
202 | |
---|
203 | /** |
---|
204 | * Return the value of an attribute in the list (by name). |
---|
205 | * |
---|
206 | * The return value is the same as the return value for |
---|
207 | * getValue(int). |
---|
208 | * |
---|
209 | * If the attribute name has a namespace prefix in the document, |
---|
210 | * the application must include the prefix here. |
---|
211 | * |
---|
212 | * @param name The name of the attribute in the list. |
---|
213 | * @return The attribute value as a string, or null if |
---|
214 | * no such attribute exists. |
---|
215 | * @see #getValue(int) |
---|
216 | * @see #getValue(XMLCh*) |
---|
217 | */ |
---|
218 | virtual const XMLCh* getValue(const char* const name) const = 0; |
---|
219 | //@} |
---|
220 | |
---|
221 | private : |
---|
222 | /* Constructors and operators */ |
---|
223 | /* Copy constructor */ |
---|
224 | AttributeList(const AttributeList&); |
---|
225 | /* Assignment operator */ |
---|
226 | AttributeList& operator=(const AttributeList&); |
---|
227 | |
---|
228 | }; |
---|
229 | |
---|
230 | XERCES_CPP_NAMESPACE_END |
---|
231 | |
---|
232 | #endif |
---|