source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/sax2/ContentHandler.hpp @ 2674

Revision 2674, 12.0 KB checked in by mattausch, 16 years ago (diff)
Line 
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: ContentHandler.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22
23#ifndef CONTENTHANDLER_HPP
24#define CONTENTHANDLER_HPP
25
26#include <xercesc/util/XercesDefs.hpp>
27
28XERCES_CPP_NAMESPACE_BEGIN
29
30class Attributes;
31class Locator;
32
33/**
34  * Receive notification of general document events.
35  *
36  * <p>This is the main interface that most SAX2 applications
37  * implement: if the application needs to be informed of basic parsing
38  * events, it implements this interface and registers an instance with
39  * the SAX2 parser using the setDocumentHandler method.  The parser
40  * uses the instance to report basic document-related events like
41  * the start and end of elements and character data.</p>
42  *
43  * <p>The order of events in this interface is very important, and
44  * mirrors the order of information in the document itself.  For
45  * example, all of an element's content (character data, processing
46  * instructions, and/or subelements) will appear, in order, between
47  * the startElement event and the corresponding endElement event.</p>
48  *
49  * <p>Application writers who do not want to implement the entire
50  * interface while can derive a class from Sax2HandlerBase, which implements
51  * the default functionality; parser writers can instantiate
52  * Sax2HandlerBase to obtain a default handler.  The application can find
53  * the location of any document event using the Locator interface
54  * supplied by the Parser through the setDocumentLocator method.</p>
55  *
56  * @see Parser#setDocumentHandler
57  * @see Locator#Locator
58  * @see Sax2HandlerBase#Sax2HandlerBase
59  */
60
61class SAX2_EXPORT ContentHandler
62{
63public:
64    /** @name Constructors and Destructor */
65    //@{
66    /** Default constructor */
67    ContentHandler()
68    {
69    }
70
71    /** Destructor */
72    virtual ~ContentHandler()
73    {
74    }
75    //@}
76
77    /** @name The virtual document handler interface */
78
79    //@{
80   /**
81    * Receive notification of character data.
82    *
83    * <p>The Parser will call this method to report each chunk of
84    * character data.  SAX parsers may return all contiguous character
85    * data in a single chunk, or they may split it into several
86    * chunks; however, all of the characters in any single event
87    * must come from the same external entity, so that the Locator
88    * provides useful information.</p>
89    *
90    * <p>The application must not attempt to read from the array
91    * outside of the specified range.</p>
92    *
93    * <p>Note that some parsers will report whitespace using the
94    * ignorableWhitespace() method rather than this one (validating
95    * parsers must do so).</p>
96    *
97    * @param chars The characters from the XML document.
98    * @param length The number of characters to read from the array.
99    * @exception SAXException Any SAX exception, possibly
100    *            wrapping another exception.
101    * @see #ignorableWhitespace
102    * @see Locator#Locator
103    */
104    virtual void characters
105    (
106        const   XMLCh* const    chars
107        , const unsigned int    length
108    ) = 0;
109
110  /**
111    * Receive notification of the end of a document.
112    *
113    * <p>The SAX parser will invoke this method only once, and it will
114    * be the last method invoked during the parse.  The parser shall
115    * not invoke this method until it has either abandoned parsing
116    * (because of an unrecoverable error) or reached the end of
117    * input.</p>
118    *
119    * @exception SAXException Any SAX exception, possibly
120    *            wrapping another exception.
121    */
122    virtual void endDocument () = 0;
123
124  /**
125    * Receive notification of the end of an element.
126    *
127    * <p>The SAX parser will invoke this method at the end of every
128    * element in the XML document; there will be a corresponding
129    * startElement() event for every endElement() event (even when the
130    * element is empty).</p>
131    *
132    * @param uri The URI of the asscioated namespace for this element
133        * @param localname The local part of the element name
134        * @param qname The QName of this element
135    * @exception SAXException Any SAX exception, possibly
136    *            wrapping another exception.
137    */
138    virtual void endElement
139        (
140                const XMLCh* const uri,
141                const XMLCh* const localname,
142                const XMLCh* const qname
143        ) = 0;
144
145  /**
146    * Receive notification of ignorable whitespace in element content.
147    *
148    * <p>Validating Parsers must use this method to report each chunk
149    * of ignorable whitespace (see the W3C XML 1.0 recommendation,
150    * section 2.10): non-validating parsers may also use this method
151    * if they are capable of parsing and using content models.</p>
152    *
153    * <p>SAX parsers may return all contiguous whitespace in a single
154    * chunk, or they may split it into several chunks; however, all of
155    * the characters in any single event must come from the same
156    * external entity, so that the Locator provides useful
157    * information.</p>
158    *
159    * <p>The application must not attempt to read from the array
160    * outside of the specified range.</p>
161    *
162    * @param chars The characters from the XML document.
163    * @param length The number of characters to read from the array.
164    * @exception SAXException Any SAX exception, possibly
165    *            wrapping another exception.
166    * @see #characters
167    */
168    virtual void ignorableWhitespace
169    (
170        const   XMLCh* const    chars
171        , const unsigned int    length
172    ) = 0;
173
174  /**
175    * Receive notification of a processing instruction.
176    *
177    * <p>The Parser will invoke this method once for each processing
178    * instruction found: note that processing instructions may occur
179    * before or after the main document element.</p>
180    *
181    * <p>A SAX parser should never report an XML declaration (XML 1.0,
182    * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
183    * using this method.</p>
184    *
185    * @param target The processing instruction target.
186    * @param data The processing instruction data, or null if
187    *        none was supplied.
188    * @exception SAXException Any SAX exception, possibly
189    *            wrapping another exception.
190    */
191    virtual void processingInstruction
192    (
193        const   XMLCh* const    target
194        , const XMLCh* const    data
195    ) = 0;
196
197  /**
198    * Receive an object for locating the origin of SAX document events.
199    *
200    * SAX parsers are strongly encouraged (though not absolutely
201    * required) to supply a locator: if it does so, it must supply
202    * the locator to the application by invoking this method before
203    * invoking any of the other methods in the DocumentHandler
204    * interface.
205    *
206    * The locator allows the application to determine the end
207    * position of any document-related event, even if the parser is
208    * not reporting an error.  Typically, the application will
209    * use this information for reporting its own errors (such as
210    * character content that does not match an application's
211    * business rules). The information returned by the locator
212    * is probably not sufficient for use with a search engine.
213    *
214    * Note that the locator will return correct information only
215    * during the invocation of the events in this interface. The
216    * application should not attempt to use it at any other time.
217    *
218    * @param locator An object that can return the location of
219    *                any SAX document event. The object is only
220    *                'on loan' to the client code and they are not
221    *                to attempt to delete or modify it in any way!
222    *
223    * @see Locator#Locator
224    */
225    virtual void setDocumentLocator(const Locator* const locator) = 0;
226
227  /**
228    * Receive notification of the beginning of a document.
229    *
230    * <p>The SAX parser will invoke this method only once, before any
231    * other methods in this interface or in DTDHandler (except for
232    * setDocumentLocator).</p>
233    *
234    * @exception SAXException Any SAX exception, possibly
235    *            wrapping another exception.
236    */
237    virtual void startDocument() = 0;
238
239  /**
240    * Receive notification of the beginning of an element.
241    *
242    * <p>The Parser will invoke this method at the beginning of every
243    * element in the XML document; there will be a corresponding
244    * endElement() event for every startElement() event (even when the
245    * element is empty). All of the element's content will be
246    * reported, in order, before the corresponding endElement()
247    * event.</p>
248    *
249    * <p>Note that the attribute list provided will
250    * contain only attributes with explicit values (specified or
251    * defaulted): #IMPLIED attributes will be omitted.</p>
252    *
253    * @param uri The URI of the asscioated namespace for this element
254        * @param localname The local part of the element name
255        * @param qname The QName of this element
256    * @param attrs The attributes attached to the element, if any.
257    * @exception SAXException Any SAX exception, possibly
258    *            wrapping another exception.
259    * @see #endElement
260    * @see Attributes#Attributes
261    */
262    virtual void startElement
263    (
264        const   XMLCh* const    uri,
265        const   XMLCh* const    localname,
266        const   XMLCh* const    qname,
267        const   Attributes&     attrs
268    ) = 0;
269
270  /**
271    * Receive notification of the start of an namespace prefix mapping.
272    *
273    * <p>By default, do nothing.  Application writers may override this
274    * method in a subclass to take specific actions at the start of
275    * each namespace prefix mapping.</p>
276    *
277    * @param prefix The namespace prefix used
278    * @param uri The namespace URI used.
279    * @exception SAXException Any SAX exception, possibly
280    *            wrapping another exception.
281    */
282        virtual void startPrefixMapping
283        (
284                const   XMLCh* const    prefix,
285                const   XMLCh* const    uri
286        ) = 0 ;
287
288  /**
289    * Receive notification of the end of an namespace prefix mapping.
290    *
291    * <p>By default, do nothing.  Application writers may override this
292    * method in a subclass to take specific actions at the end of
293    * each namespace prefix mapping.</p>
294    *
295    * @param prefix The namespace prefix used
296    * @exception SAXException Any SAX exception, possibly
297    *            wrapping another exception.
298    */
299        virtual void endPrefixMapping
300        (
301                const   XMLCh* const    prefix
302        ) = 0 ;
303
304  /**
305    * Receive notification of a skipped entity
306    *
307    * <p>The parser will invoke this method once for each entity
308        * skipped.  All processors may skip external entities,
309        * depending on the values of the features:<br>
310        * http://xml.org/sax/features/external-general-entities<br>
311        * http://xml.org/sax/features/external-parameter-entities</p>
312        *
313        * <p>Note: Xerces (specifically) never skips any entities, regardless
314        * of the above features.  This function is never called in the
315        * Xerces implementation of SAX2.</p>
316    *
317        * <p>Introduced with SAX2</p>
318        *
319    * @param name The name of the skipped entity.  If it is a parameter entity,
320        * the name will begin with %, and if it is the external DTD subset,
321        * it will be the string [dtd].
322    * @exception SAXException Any SAX exception, possibly
323    *            wrapping another exception.
324    */
325        virtual void skippedEntity
326        (
327                const   XMLCh* const    name
328        ) = 0 ;
329
330    //@}
331private :
332    /* Unimplemented Constructors and operators */
333    /* Copy constructor */
334    ContentHandler(const ContentHandler&);
335    /** Assignment operator */
336    ContentHandler& operator=(const ContentHandler&);
337};
338
339XERCES_CPP_NAMESPACE_END
340
341#endif
Note: See TracBrowser for help on using the repository browser.