source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/sax/DocumentHandler.hpp @ 2674

Revision 2674, 10.1 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: DocumentHandler.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22
23#ifndef DOCUMENTHANDLER_HPP
24#define DOCUMENTHANDLER_HPP
25
26#include <xercesc/util/XercesDefs.hpp>
27
28XERCES_CPP_NAMESPACE_BEGIN
29
30class AttributeList;
31class Locator;
32
33/**
34  * Receive notification of general document events.
35  *
36  * <p>This is the main interface that most SAX 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 SAX 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 HandlerBase, which implements
51  * the default functionality; parser writers can instantiate
52  * HandlerBase 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 HandlerBase#HandlerBase
59  */
60
61class SAX_EXPORT DocumentHandler
62{
63public:
64    /** @name Constructors and Destructor */
65    //@{
66    /** Default constructor */
67    DocumentHandler()
68    {
69    }
70
71    /** Destructor */
72    virtual ~DocumentHandler()
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    * <p>If the element name has a namespace prefix, the prefix will
133    * still be attached to the name.</p>
134    *
135    * @param name The element type name
136    * @exception SAXException Any SAX exception, possibly
137    *            wrapping another exception.
138    */
139    virtual void endElement(const XMLCh* const name) = 0;
140
141  /**
142    * Receive notification of ignorable whitespace in element content.
143    *
144    * <p>Validating Parsers must use this method to report each chunk
145    * of ignorable whitespace (see the W3C XML 1.0 recommendation,
146    * section 2.10): non-validating parsers may also use this method
147    * if they are capable of parsing and using content models.</p>
148    *
149    * <p>SAX parsers may return all contiguous whitespace in a single
150    * chunk, or they may split it into several chunks; however, all of
151    * the characters in any single event must come from the same
152    * external entity, so that the Locator provides useful
153    * information.</p>
154    *
155    * <p>The application must not attempt to read from the array
156    * outside of the specified range.</p>
157    *
158    * @param chars The characters from the XML document.
159    * @param length The number of characters to read from the array.
160    * @exception SAXException Any SAX exception, possibly
161    *            wrapping another exception.
162    * @see #characters
163    */
164    virtual void ignorableWhitespace
165    (
166        const   XMLCh* const    chars
167        , const unsigned int    length
168    ) = 0;
169
170  /**
171    * Receive notification of a processing instruction.
172    *
173    * <p>The Parser will invoke this method once for each processing
174    * instruction found: note that processing instructions may occur
175    * before or after the main document element.</p>
176    *
177    * <p>A SAX parser should never report an XML declaration (XML 1.0,
178    * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
179    * using this method.</p>
180    *
181    * @param target The processing instruction target.
182    * @param data The processing instruction data, or null if
183    *        none was supplied.
184    * @exception SAXException Any SAX exception, possibly
185    *            wrapping another exception.
186    */
187    virtual void processingInstruction
188    (
189        const   XMLCh* const    target
190        , const XMLCh* const    data
191    ) = 0;
192
193    /**
194    * Reset the Docuemnt object on its reuse
195    *
196    * <p>This method helps in reseting the document implementational
197    * defaults each time the document is begun.</p>
198    *
199    */
200    virtual void resetDocument() = 0;
201
202  /**
203    * Receive an object for locating the origin of SAX document events.
204    *
205    * SAX parsers are strongly encouraged (though not absolutely
206    * required) to supply a locator: if it does so, it must supply
207    * the locator to the application by invoking this method before
208    * invoking any of the other methods in the DocumentHandler
209    * interface.
210    *
211    * The locator allows the application to determine the end
212    * position of any document-related event, even if the parser is
213    * not reporting an error.  Typically, the application will
214    * use this information for reporting its own errors (such as
215    * character content that does not match an application's
216    * business rules). The information returned by the locator
217    * is probably not sufficient for use with a search engine.
218    *
219    * Note that the locator will return correct information only
220    * during the invocation of the events in this interface. The
221    * application should not attempt to use it at any other time.
222    *
223    * @param locator An object that can return the location of
224    *                any SAX document event. The object is only
225    *                'on loan' to the client code and they are not
226    *                to attempt to delete or modify it in any way!
227    *
228    * @see Locator#Locator
229    */
230    virtual void setDocumentLocator(const Locator* const locator) = 0;
231
232  /**
233    * Receive notification of the beginning of a document.
234    *
235    * <p>The SAX parser will invoke this method only once, before any
236    * other methods in this interface or in DTDHandler (except for
237    * setDocumentLocator).</p>
238    *
239    * @exception SAXException Any SAX exception, possibly
240    *            wrapping another exception.
241    */
242    virtual void startDocument() = 0;
243
244  /**
245    * Receive notification of the beginning of an element.
246    *
247    * <p>The Parser will invoke this method at the beginning of every
248    * element in the XML document; there will be a corresponding
249    * endElement() event for every startElement() event (even when the
250    * element is empty). All of the element's content will be
251    * reported, in order, before the corresponding endElement()
252    * event.</p>
253    *
254    * <p>If the element name has a namespace prefix, the prefix will
255    * still be attached.  Note that the attribute list provided will
256    * contain only attributes with explicit values (specified or
257    * defaulted): #IMPLIED attributes will be omitted.</p>
258    *
259    * @param name The element type name.
260    * @param attrs The attributes attached to the element, if any.
261    * @exception SAXException Any SAX exception, possibly
262    *            wrapping another exception.
263    * @see #endElement
264    * @see AttributeList#AttributeList
265    */
266    virtual void startElement
267    (
268        const   XMLCh* const    name
269        ,       AttributeList&  attrs
270    ) = 0;
271
272    //@}
273
274private :
275    /* Unimplemented Constructors and operators */
276    /* Copy constructor */
277    DocumentHandler(const DocumentHandler&);
278    /** Assignment operator */
279    DocumentHandler& operator=(const DocumentHandler&);
280};
281
282XERCES_CPP_NAMESPACE_END
283
284#endif
Note: See TracBrowser for help on using the repository browser.