1 | // |
---|
2 | // ContentHandler.h |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/XML/include/Poco/SAX/ContentHandler.h#2 $ |
---|
5 | // |
---|
6 | // Library: XML |
---|
7 | // Package: SAX |
---|
8 | // Module: SAX |
---|
9 | // |
---|
10 | // SAX2 ContentHandler Interface. |
---|
11 | // |
---|
12 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
13 | // and Contributors. |
---|
14 | // |
---|
15 | // Permission is hereby granted, free of charge, to any person or organization |
---|
16 | // obtaining a copy of the software and accompanying documentation covered by |
---|
17 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
18 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
19 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
20 | // do so, all subject to the following: |
---|
21 | // |
---|
22 | // The copyright notices in the Software and this entire statement, including |
---|
23 | // the above license grant, this restriction and the following disclaimer, |
---|
24 | // must be included in all copies of the Software, in whole or in part, and |
---|
25 | // all derivative works of the Software, unless such copies or derivative |
---|
26 | // works are solely in the form of machine-executable object code generated by |
---|
27 | // a source language processor. |
---|
28 | // |
---|
29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
35 | // DEALINGS IN THE SOFTWARE. |
---|
36 | // |
---|
37 | |
---|
38 | |
---|
39 | #ifndef SAX_ContentHandler_INCLUDED |
---|
40 | #define SAX_ContentHandler_INCLUDED |
---|
41 | |
---|
42 | |
---|
43 | #include "Poco/XML/XML.h" |
---|
44 | #include "Poco/XML/XMLString.h" |
---|
45 | |
---|
46 | |
---|
47 | namespace Poco { |
---|
48 | namespace XML { |
---|
49 | |
---|
50 | |
---|
51 | class Locator; |
---|
52 | class Attributes; |
---|
53 | |
---|
54 | |
---|
55 | class XML_API ContentHandler |
---|
56 | /// Receive notification of the logical content of a document. |
---|
57 | /// |
---|
58 | /// This is the main interface that most SAX applications implement: if the |
---|
59 | /// application needs to be informed of basic parsing events, it implements |
---|
60 | /// this interface and registers an instance with the SAX parser using the setContentHandler |
---|
61 | /// method. The parser uses the instance to report basic document-related events |
---|
62 | /// like the start and end of elements and character data. |
---|
63 | /// |
---|
64 | /// The order of events in this interface is very important, and mirrors the |
---|
65 | /// order of information in the document itself. For example, all of an element's |
---|
66 | /// content (character data, processing instructions, and/or subelements) will |
---|
67 | /// appear, in order, between the startElement event and the corresponding endElement |
---|
68 | /// event. |
---|
69 | /// |
---|
70 | /// This interface is similar to the now-deprecated SAX 1.0 DocumentHandler |
---|
71 | /// interface, but it adds support for Namespaces and for reporting skipped |
---|
72 | /// entities (in non-validating XML processors). |
---|
73 | /// Receive notification of the logical content of a document. |
---|
74 | { |
---|
75 | public: |
---|
76 | virtual void setDocumentLocator(const Locator* loc) = 0; |
---|
77 | /// Receive an object for locating the origin of SAX document events. |
---|
78 | /// |
---|
79 | /// SAX parsers are strongly encouraged (though not absolutely required) to |
---|
80 | /// supply a locator: if it does so, it must supply the locator to the application |
---|
81 | /// by invoking this method before invoking any of the other methods in the |
---|
82 | /// ContentHandler interface. |
---|
83 | /// |
---|
84 | /// The locator allows the application to determine the end position of any |
---|
85 | /// document-related event, even if the parser is not reporting an error. Typically, |
---|
86 | /// the application will use this information for reporting its own errors (such |
---|
87 | /// as character content that does not match an application's business rules). |
---|
88 | /// The information returned by the locator is probably not sufficient for use |
---|
89 | /// with a search engine. |
---|
90 | /// |
---|
91 | /// Note that the locator will return correct information only during the invocation |
---|
92 | /// SAX event callbacks after startDocument returns and before endDocument is |
---|
93 | /// called. The application should not attempt to use it at any other time. |
---|
94 | |
---|
95 | virtual void startDocument() = 0; |
---|
96 | /// Receive notification of the beginning of a document. |
---|
97 | /// |
---|
98 | /// The SAX parser calls this function one time before calling all other |
---|
99 | /// functions of this class (except SetDocumentLocator). |
---|
100 | |
---|
101 | virtual void endDocument() = 0; |
---|
102 | /// Receive notification of the end of a document. |
---|
103 | /// |
---|
104 | /// The SAX parser will invoke this method only once, and it will be the last |
---|
105 | /// method invoked during the parse. The parser shall not invoke this method |
---|
106 | /// until it has either abandoned parsing (because of an unrecoverable error) |
---|
107 | /// or reached the end of input. |
---|
108 | |
---|
109 | virtual void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList) = 0; |
---|
110 | /// Receive notification of the beginning of an element. |
---|
111 | /// |
---|
112 | /// The Parser will invoke this method at the beginning of every element in |
---|
113 | /// the XML document; there will be a corresponding endElement event for every |
---|
114 | /// startElement event (even when the element is empty). All of the element's |
---|
115 | /// content will be reported, in order, before the corresponding endElement |
---|
116 | /// event. |
---|
117 | /// |
---|
118 | /// This event allows up to three name components for each element: |
---|
119 | /// 1. the Namespace URI; |
---|
120 | /// 2. the local name; and |
---|
121 | /// 3. the qualified (prefixed) name. |
---|
122 | /// |
---|
123 | /// Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces |
---|
124 | /// and the http://xml.org/sax/features/namespace-prefixes properties: |
---|
125 | /// * the Namespace URI and local name are required when the namespaces |
---|
126 | /// property is true (the default), and are optional when the namespaces property |
---|
127 | /// is false (if one is specified, both must be); |
---|
128 | /// * the qualified name is required when the namespace-prefixes property |
---|
129 | /// is true, and is optional when the namespace-prefixes property is false (the |
---|
130 | /// default). |
---|
131 | /// |
---|
132 | /// Note that the attribute list provided will contain only attributes with |
---|
133 | /// explicit values (specified or defaulted): #IMPLIED attributes will be omitted. |
---|
134 | /// The attribute list will contain attributes used for Namespace declarations |
---|
135 | /// (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes |
---|
136 | /// property is true (it is false by default, and support for a true value is |
---|
137 | /// optional). |
---|
138 | /// |
---|
139 | /// Like characters(), attribute values may have characters that need more than |
---|
140 | /// one char value. |
---|
141 | |
---|
142 | virtual void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) = 0; |
---|
143 | /// Receive notification of the end of an element. |
---|
144 | /// |
---|
145 | /// The SAX parser will invoke this method at the end of every element in the |
---|
146 | /// XML document; there will be a corresponding startElement event for every |
---|
147 | /// endElement event (even when the element is empty). |
---|
148 | /// |
---|
149 | /// For information on the names, see startElement. |
---|
150 | |
---|
151 | virtual void characters(const XMLChar ch[], int start, int length) = 0; |
---|
152 | /// Receive notification of character data. |
---|
153 | /// |
---|
154 | /// The Parser will call this method to report each chunk of character data. |
---|
155 | /// SAX parsers may return all contiguous character data in a single chunk, |
---|
156 | /// or they may split it into several chunks; however, all of the characters |
---|
157 | /// in any single event must come from the same external entity so that the |
---|
158 | /// Locator provides useful information. |
---|
159 | /// |
---|
160 | /// The application must not attempt to read from the array outside of the specified |
---|
161 | /// range. |
---|
162 | /// |
---|
163 | /// Individual characters may consist of more than one XMLChar value. There |
---|
164 | /// are three important cases where this happens, because characters can't be |
---|
165 | /// represented in just sixteen bits. In one case, characters are represented |
---|
166 | /// in a Surrogate Pair, using two special Unicode values. Such characters are |
---|
167 | /// in the so-called "Astral Planes", with a code point above U+FFFF. A second |
---|
168 | /// case involves composite characters, such as a base character combining with |
---|
169 | /// one or more accent characters. And most important, if XMLChar is a plain |
---|
170 | /// char, characters are encoded in UTF-8. |
---|
171 | /// |
---|
172 | /// Your code should not assume that algorithms using char-at-a-time idioms |
---|
173 | /// will be working in character units; in some cases they will split characters. |
---|
174 | /// This is relevant wherever XML permits arbitrary characters, such as attribute |
---|
175 | /// values, processing instruction data, and comments as well as in data reported |
---|
176 | /// from this method. It's also generally relevant whenever C++ code manipulates |
---|
177 | /// internationalized text; the issue isn't unique to XML. |
---|
178 | /// |
---|
179 | /// Note that some parsers will report whitespace in element content using the |
---|
180 | /// ignorableWhitespace method rather than this one (validating parsers must |
---|
181 | /// do so). |
---|
182 | |
---|
183 | virtual void ignorableWhitespace(const XMLChar ch[], int start, int length) = 0; |
---|
184 | /// Receive notification of ignorable whitespace in element content. |
---|
185 | /// |
---|
186 | /// Validating Parsers must use this method to report each chunk of whitespace |
---|
187 | /// in element content (see the W3C XML 1.0 recommendation, section 2.10): non-validating |
---|
188 | /// parsers may also use this method if they are capable of parsing and using |
---|
189 | /// content models. |
---|
190 | /// |
---|
191 | /// SAX parsers may return all contiguous whitespace in a single chunk, or they |
---|
192 | /// may split it into several chunks; however, all of the characters in any |
---|
193 | /// single event must come from the same external entity, so that the Locator |
---|
194 | /// provides useful information. |
---|
195 | /// |
---|
196 | /// The application must not attempt to read from the array outside of the specified |
---|
197 | /// range. |
---|
198 | |
---|
199 | virtual void processingInstruction(const XMLString& target, const XMLString& data) = 0; |
---|
200 | /// Receive notification of a processing instruction. |
---|
201 | /// |
---|
202 | /// The Parser will invoke this method once for each processing instruction |
---|
203 | /// found: note that processing instructions may occur before or after the main |
---|
204 | /// document element. |
---|
205 | /// |
---|
206 | /// A SAX parser must never report an XML declaration (XML 1.0, section 2.8) |
---|
207 | /// or a text declaration (XML 1.0, section 4.3.1) using this method. |
---|
208 | /// |
---|
209 | /// Like characters(), processing instruction data may have characters that |
---|
210 | /// need more than one char value. |
---|
211 | |
---|
212 | virtual void startPrefixMapping(const XMLString& prefix, const XMLString& uri) = 0; |
---|
213 | /// Begin the scope of a prefix-URI Namespace mapping. |
---|
214 | /// |
---|
215 | /// The information from this event is not necessary for normal Namespace processing: |
---|
216 | /// the SAX XML reader will automatically replace prefixes for element and attribute |
---|
217 | /// names when the http://xml.org/sax/features/namespaces feature is true (the |
---|
218 | /// default). |
---|
219 | /// |
---|
220 | /// There are cases, however, when applications need to use prefixes in character |
---|
221 | /// data or in attribute values, where they cannot safely be expanded automatically; |
---|
222 | /// the start/endPrefixMapping event supplies the information to the application |
---|
223 | /// to expand prefixes in those contexts itself, if necessary. |
---|
224 | /// |
---|
225 | /// Note that start/endPrefixMapping events are not guaranteed to be properly |
---|
226 | /// nested relative to each other: all startPrefixMapping events will occur |
---|
227 | /// immediately before the corresponding startElement event, and all endPrefixMapping |
---|
228 | /// events will occur immediately after the corresponding endElement event, |
---|
229 | /// but their order is not otherwise guaranteed. |
---|
230 | /// |
---|
231 | /// There should never be start/endPrefixMapping events for the "xml" prefix, |
---|
232 | /// since it is predeclared and immutable. |
---|
233 | |
---|
234 | virtual void endPrefixMapping(const XMLString& prefix) = 0; |
---|
235 | /// End the scope of a prefix-URI mapping. |
---|
236 | /// |
---|
237 | /// See startPrefixMapping for details. These events will always occur immediately |
---|
238 | /// after the corresponding endElement event, but the order of endPrefixMapping |
---|
239 | /// events is not otherwise guaranteed. |
---|
240 | |
---|
241 | virtual void skippedEntity(const XMLString& name) = 0; |
---|
242 | /// Receive notification of a skipped entity. This is not called for entity |
---|
243 | /// references within markup constructs such as element start tags or markup |
---|
244 | /// declarations. (The XML recommendation requires reporting skipped external |
---|
245 | /// entities. SAX also reports internal entity expansion/non-expansion, except |
---|
246 | /// within markup constructs.) |
---|
247 | /// |
---|
248 | /// The Parser will invoke this method each time the entity is skipped. Non-validating |
---|
249 | /// processors may skip entities if they have not seen the declarations (because, |
---|
250 | /// for example, the entity was declared in an external DTD subset). All processors |
---|
251 | /// may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities |
---|
252 | /// and the http://xml.org/sax/features/external-parameter-entities properties. |
---|
253 | |
---|
254 | protected: |
---|
255 | virtual ~ContentHandler(); |
---|
256 | }; |
---|
257 | |
---|
258 | |
---|
259 | } } // namespace Poco::XML |
---|
260 | |
---|
261 | |
---|
262 | #endif // SAX_ContentHandler_INCLUDED |
---|