Coverage Report

Created: 2026-04-01 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xerces-c/src/xercesc/sax/DocumentHandler.hpp
Line
Count
Source
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 932889 2010-04-11 13:10:10Z borisk $
20
 */
21
22
#if !defined(XERCESC_INCLUDE_GUARD_DOCUMENTHANDLER_HPP)
23
#define XERCESC_INCLUDE_GUARD_DOCUMENTHANDLER_HPP
24
25
#include <xercesc/util/XercesDefs.hpp>
26
27
XERCES_CPP_NAMESPACE_BEGIN
28
29
class AttributeList;
30
class Locator;
31
32
/**
33
  * Receive notification of general document events.
34
  *
35
  * <p>This is the main interface that most SAX applications
36
  * implement: if the application needs to be informed of basic parsing
37
  * events, it implements this interface and registers an instance with
38
  * the SAX parser using the setDocumentHandler method.  The parser
39
  * uses the instance to report basic document-related events like
40
  * the start and end of elements and character data.</p>
41
  *
42
  * <p>The order of events in this interface is very important, and
43
  * mirrors the order of information in the document itself.  For
44
  * example, all of an element's content (character data, processing
45
  * instructions, and/or subelements) will appear, in order, between
46
  * the startElement event and the corresponding endElement event.</p>
47
  *
48
  * <p>Application writers who do not want to implement the entire
49
  * interface while can derive a class from HandlerBase, which implements
50
  * the default functionality; parser writers can instantiate
51
  * HandlerBase to obtain a default handler.  The application can find
52
  * the location of any document event using the Locator interface
53
  * supplied by the Parser through the setDocumentLocator method.</p>
54
  *
55
  * @see Parser#setDocumentHandler
56
  * @see Locator#Locator
57
  * @see HandlerBase#HandlerBase
58
  */
59
60
class SAX_EXPORT DocumentHandler
61
{
62
public:
63
    /** @name Constructors and Destructor */
64
    //@{
65
    /** Default constructor */
66
    DocumentHandler()
67
0
    {
68
0
    }
69
70
    /** Destructor */
71
    virtual ~DocumentHandler()
72
0
    {
73
0
    }
74
    //@}
75
76
    /** @name The virtual document handler interface */
77
78
    //@{
79
   /**
80
    * Receive notification of character data.
81
    *
82
    * <p>The Parser will call this method to report each chunk of
83
    * character data.  SAX parsers may return all contiguous character
84
    * data in a single chunk, or they may split it into several
85
    * chunks; however, all of the characters in any single event
86
    * must come from the same external entity, so that the Locator
87
    * provides useful information.</p>
88
    *
89
    * <p>The application must not attempt to read from the array
90
    * outside of the specified range.</p>
91
    *
92
    * <p>Note that some parsers will report whitespace using the
93
    * ignorableWhitespace() method rather than this one (validating
94
    * parsers must do so).</p>
95
    *
96
    * @param chars The characters from the XML document.
97
    * @param length The number of characters to read from the array.
98
    * @exception SAXException Any SAX exception, possibly
99
    *            wrapping another exception.
100
    * @see #ignorableWhitespace
101
    * @see Locator#Locator
102
    */
103
    virtual void characters
104
    (
105
        const   XMLCh* const    chars
106
        , const XMLSize_t       length
107
    ) = 0;
108
109
  /**
110
    * Receive notification of the end of a document.
111
    *
112
    * <p>The SAX parser will invoke this method only once, and it will
113
    * be the last method invoked during the parse.  The parser shall
114
    * not invoke this method until it has either abandoned parsing
115
    * (because of an unrecoverable error) or reached the end of
116
    * input.</p>
117
    *
118
    * @exception SAXException Any SAX exception, possibly
119
    *            wrapping another exception.
120
    */
121
    virtual void endDocument () = 0;
122
123
  /**
124
    * Receive notification of the end of an element.
125
    *
126
    * <p>The SAX parser will invoke this method at the end of every
127
    * element in the XML document; there will be a corresponding
128
    * startElement() event for every endElement() event (even when the
129
    * element is empty).</p>
130
    *
131
    * <p>If the element name has a namespace prefix, the prefix will
132
    * still be attached to the name.</p>
133
    *
134
    * @param name The element type name
135
    * @exception SAXException Any SAX exception, possibly
136
    *            wrapping another exception.
137
    */
138
    virtual void endElement(const XMLCh* const name) = 0;
139
140
  /**
141
    * Receive notification of ignorable whitespace in element content.
142
    *
143
    * <p>Validating Parsers must use this method to report each chunk
144
    * of ignorable whitespace (see the W3C XML 1.0 recommendation,
145
    * section 2.10): non-validating parsers may also use this method
146
    * if they are capable of parsing and using content models.</p>
147
    *
148
    * <p>SAX parsers may return all contiguous whitespace in a single
149
    * chunk, or they may split it into several chunks; however, all of
150
    * the characters in any single event must come from the same
151
    * external entity, so that the Locator provides useful
152
    * information.</p>
153
    *
154
    * <p>The application must not attempt to read from the array
155
    * outside of the specified range.</p>
156
    *
157
    * @param chars The characters from the XML document.
158
    * @param length The number of characters to read from the array.
159
    * @exception SAXException Any SAX exception, possibly
160
    *            wrapping another exception.
161
    * @see #characters
162
    */
163
    virtual void ignorableWhitespace
164
    (
165
        const   XMLCh* const    chars
166
        , const XMLSize_t       length
167
    ) = 0;
168
169
  /**
170
    * Receive notification of a processing instruction.
171
    *
172
    * <p>The Parser will invoke this method once for each processing
173
    * instruction found: note that processing instructions may occur
174
    * before or after the main document element.</p>
175
    *
176
    * <p>A SAX parser should never report an XML declaration (XML 1.0,
177
    * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
178
    * using this method.</p>
179
    *
180
    * @param target The processing instruction target.
181
    * @param data The processing instruction data, or null if
182
    *        none was supplied.
183
    * @exception SAXException Any SAX exception, possibly
184
    *            wrapping another exception.
185
    */
186
    virtual void processingInstruction
187
    (
188
        const   XMLCh* const    target
189
        , const XMLCh* const    data
190
    ) = 0;
191
192
    /**
193
    * Reset the Document object on its reuse
194
    *
195
    * <p>This method helps in reseting the document implementation
196
    * defaults each time the document is begun.</p>
197
    *
198
    */
199
    virtual void resetDocument() = 0;
200
201
  /**
202
    * Receive an object for locating the origin of SAX document events.
203
    *
204
    * SAX parsers are strongly encouraged (though not absolutely
205
    * required) to supply a locator: if it does so, it must supply
206
    * the locator to the application by invoking this method before
207
    * invoking any of the other methods in the DocumentHandler
208
    * interface.
209
    *
210
    * The locator allows the application to determine the end
211
    * position of any document-related event, even if the parser is
212
    * not reporting an error.  Typically, the application will
213
    * use this information for reporting its own errors (such as
214
    * character content that does not match an application's
215
    * business rules). The information returned by the locator
216
    * is probably not sufficient for use with a search engine.
217
    *
218
    * Note that the locator will return correct information only
219
    * during the invocation of the events in this interface. The
220
    * application should not attempt to use it at any other time.
221
    *
222
    * @param locator An object that can return the location of
223
    *                any SAX document event. The object is only
224
    *                'on loan' to the client code and they are not
225
    *                to attempt to delete or modify it in any way!
226
    *
227
    * @see Locator#Locator
228
    */
229
    virtual void setDocumentLocator(const Locator* const locator) = 0;
230
231
  /**
232
    * Receive notification of the beginning of a document.
233
    *
234
    * <p>The SAX parser will invoke this method only once, before any
235
    * other methods in this interface or in DTDHandler (except for
236
    * setDocumentLocator).</p>
237
    *
238
    * @exception SAXException Any SAX exception, possibly
239
    *            wrapping another exception.
240
    */
241
    virtual void startDocument() = 0;
242
243
  /**
244
    * Receive notification of the beginning of an element.
245
    *
246
    * <p>The Parser will invoke this method at the beginning of every
247
    * element in the XML document; there will be a corresponding
248
    * endElement() event for every startElement() event (even when the
249
    * element is empty). All of the element's content will be
250
    * reported, in order, before the corresponding endElement()
251
    * event.</p>
252
    *
253
    * <p>If the element name has a namespace prefix, the prefix will
254
    * still be attached.  Note that the attribute list provided will
255
    * contain only attributes with explicit values (specified or
256
    * defaulted): \#IMPLIED attributes will be omitted.</p>
257
    *
258
    * @param name The element type name.
259
    * @param attrs The attributes attached to the element, if any.
260
    * @exception SAXException Any SAX exception, possibly
261
    *            wrapping another exception.
262
    * @see #endElement
263
    * @see AttributeList#AttributeList
264
    */
265
    virtual void startElement
266
    (
267
        const   XMLCh* const    name
268
        ,       AttributeList&  attrs
269
    ) = 0;
270
271
    //@}
272
273
private :
274
    /* Unimplemented Constructors and operators */
275
    /* Copy constructor */
276
    DocumentHandler(const DocumentHandler&);
277
    /** Assignment operator */
278
    DocumentHandler& operator=(const DocumentHandler&);
279
};
280
281
XERCES_CPP_NAMESPACE_END
282
283
#endif