source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/framework/XMLDocumentHandler.hpp @ 2674

Revision 2674, 11.8 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: XMLDocumentHandler.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22
23#if !defined(XMLDOCUMENTHANDLER_HPP)
24#define XMLDOCUMENTHANDLER_HPP
25
26#include <xercesc/util/XercesDefs.hpp>
27#include <xercesc/util/RefVectorOf.hpp>
28#include <xercesc/framework/XMLAttr.hpp>
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32class XMLElementDecl;
33class XMLEntityDecl;
34
35/**
36  * This abstract class provides the interface for the scanner to return
37  * XML document information up to the parser as it scans through the
38  * document.
39  *
40  * The interface is very similar to org.sax.DocumentHandler, but
41  * has some extra methods required to get all the data out.
42  */
43class XMLPARSER_EXPORT XMLDocumentHandler
44{
45public:
46    // -----------------------------------------------------------------------
47    //  Constructors are hidden, just the virtual destructor is exposed
48    // -----------------------------------------------------------------------
49    /** @name Destructor */
50    //@{
51    virtual ~XMLDocumentHandler()
52    {
53    }
54    //@}
55
56    /** @name The document handler interface */
57    //@{
58    /** Receive notification of character data.
59      *
60      * <p>The scanner will call this method to report each chunk of
61      * character data. The scanner may return all contiguous character
62      * data in a single chunk, or they may split it into several
63      * chunks; however, all of the characters in any single event
64      * will come from the same external entity, so that the Locator
65      * provides useful information.</p>
66      *
67      * <p>The parser must not attempt to read from the array
68      * outside of the specified range.</p>
69      *
70      * @param  chars           The content (characters) between markup from the XML
71      *                         document.
72      * @param  length          The number of characters to read from the array.
73      * @param  cdataSection    Indicates that this data is inside a CDATA
74      *                         section.
75      * @see #ignorableWhitespace
76      * @see Locator
77      */
78    virtual void docCharacters
79    (
80        const   XMLCh* const    chars
81        , const unsigned int    length
82        , const bool            cdataSection
83    ) = 0;
84
85    /** Receive notification of comments in the XML content being parsed.
86      *
87      * This scanner will call this method for any comments found in the
88      * content of the document.
89      *
90      * @param comment The text of the comment.
91      */
92    virtual void docComment
93    (
94        const   XMLCh* const    comment
95    ) = 0;
96
97    /** Receive notification of PI's parsed in the XML content.
98      *
99      * The scanner will call this method for any PIs it finds within the
100      * content of the document.
101      *
102      * @param  target  The name of the PI.
103      * @param  data    The body of the PI. This may be an empty string since
104      *                 the body is optional.
105      */
106    virtual void docPI
107    (
108        const   XMLCh* const    target
109        , const XMLCh* const    data
110    ) = 0;
111
112    /** Receive notification after the scanner has parsed the end of the
113      * document.
114      *
115      * The scanner will call this method when the current document has been
116      * fully parsed. The handler may use this opportunity to do something with
117      * the data, clean up temporary data, etc...
118      */
119    virtual void endDocument() = 0;
120
121    /** Receive notification of the end of an element.
122      *
123      * This method is called when scanner encounters the end of element tag.
124      * There will be a corresponding startElement() event for every
125      * endElement() event, but not necessarily the other way around. For
126      * empty tags, there is only a startElement() call.
127      *
128      * @param  elemDecl The name of the element whose end tag was just
129      *                     parsed.
130      * @param  uriId       The ID of the URI in the URI pool (only valid if
131      *                     name spaces is enabled)
132      * @param  isRoot      Indicates if this is the root element.
133      * @param  prefixName  The string representing the prefix name
134      */
135    virtual void endElement
136    (
137        const   XMLElementDecl& elemDecl
138        , const unsigned int    uriId
139        , const bool            isRoot
140        , const XMLCh* const    prefixName = 0
141    ) = 0;
142
143    /** Receive notification when a referenced entity's content ends
144      *
145      * This method is called when scanner encounters the end of an entity
146      * reference.
147      *
148      * @param  entDecl  The name of the entity reference just scanned.
149      */
150    virtual void endEntityReference
151    (
152        const   XMLEntityDecl&  entDecl
153    ) = 0;
154
155    /** Receive notification of ignorable whitespace in element content.
156      *
157      * <p>Validating Parsers must use this method to report each chunk
158      * of ignorable whitespace (see the W3C XML 1.0 recommendation,
159      * section 2.10): non-validating parsers may also use this method
160      * if they are capable of parsing and using content models.</p>
161      *
162      * <p>The scanner may return all contiguous whitespace in a single
163      * chunk, or it may split it into several chunks; however, all of
164      * the characters in any single event will come from the same
165      * external entity, so that the Locator provides useful
166      * information.</p>
167      *
168      * <p>The parser must not attempt to read from the array
169      * outside of the specified range.</p>
170      *
171      * @param  chars       The whitespace characters from the XML document.
172      * @param  length      The number of characters to read from the array.
173      * @param  cdataSection Indicates that this data is inside a CDATA
174      *                     section.
175      * @see #characters
176      */
177    virtual void ignorableWhitespace
178    (
179        const   XMLCh* const    chars
180        , const unsigned int    length
181        , const bool            cdataSection
182    ) = 0;
183
184    /** Reset the document handler's state, if required
185      *
186      * This method is used to give the registered document handler a
187      * chance to reset itself. Its called by the scanner at the start of
188      * every parse.
189      */
190    virtual void resetDocument() = 0;
191
192    /** Receive notification of the start of a new document
193      *
194      * This method is the first callback called the scanner at the
195      * start of every parse. This is before any content is parsed.
196      */
197    virtual void startDocument() = 0;
198
199    /** Receive notification of a new start tag
200      *
201      * This method is called when scanner encounters the start of an element tag.
202      * All elements must always have a startElement() tag. Empty tags will
203      * only have the startElement() tag and no endElement() tag.
204      *
205      * @param  elemDecl The name of the element whose start tag was just
206      *                     parsed.
207      * @param  uriId       The ID of the URI in the URI pool (only valid if
208      *                     name spaces is enabled)
209      * @param  prefixName  The string representing the prefix name
210      * @param  attrList    List of attributes in the element
211      * @param  attrCount   Count of the attributes in the element
212      * @param  isEmpty     Indicates if the element is empty, in which case
213      *                     you should not expect an endElement() event.
214      * @param  isRoot      Indicates if this is the root element.
215      */
216    virtual void startElement
217    (
218        const   XMLElementDecl&         elemDecl
219        , const unsigned int            uriId
220        , const XMLCh* const            prefixName
221        , const RefVectorOf<XMLAttr>&   attrList
222        , const unsigned int            attrCount
223        , const bool                    isEmpty
224        , const bool                    isRoot
225    ) = 0;
226
227    /** Receive notification when the scanner hits an entity reference.
228      *
229      * This is currently useful only to DOM parser configurations as SAX
230      * does not provide any api to return this information.
231      *
232      * @param  entDecl  The name of the entity that was referenced.
233      */
234    virtual void startEntityReference(const XMLEntityDecl& entDecl) = 0;
235
236    /** Receive notification of an XML declaration
237      *
238      * Currently neither DOM nor SAX provide API's to return back this
239      * information.
240      *
241      * @param  versionStr      The value of the <code>version</code> pseudoattribute
242      *                         of the XML decl.
243      * @param  encodingStr     The value of the <code>encoding</code> pseudoattribute
244      *                         of the XML decl.
245      * @param  standaloneStr   The value of the <code>standalone</code>
246      *                         pseudoattribute of the XML decl.
247      * @param  autoEncodingStr The encoding string auto-detected by the
248      *                         scanner. In absence of any 'encoding' attribute in the
249      *                         XML decl, the XML standard specifies how a parser can
250      *                         auto-detect. If there is no <code>encodingStr</code>
251      *                         this is what will be used to try to decode the file.
252      */
253    virtual void XMLDecl
254    (
255        const   XMLCh* const    versionStr
256        , const XMLCh* const    encodingStr
257        , const XMLCh* const    standaloneStr
258        , const XMLCh* const    autoEncodingStr
259    ) = 0;
260
261    /** Receive notification of the name and namespace of the type that validated
262      * the element corresponding to the most recent endElement event.
263      * This event will be fired immediately after the
264      * endElement() event that signifies the end of the element
265      * to which it applies; no other events will intervene.
266      * This method is <em>EXPERIMENTAL</em> and may change, disappear
267      * or become pure virtual at any time.
268      *
269      * This corresponds to a part of the information required by DOM Core
270      * level 3's TypeInfo interface.
271      *
272      * @param  typeName        local name of the type that actually validated
273      *                         the content of the element corresponding to the
274      *                         most recent endElement() callback
275      * @param  typeURI         namespace of the type that actually validated
276      *                         the content of the element corresponding to the
277      *                         most recent endElement() callback
278      * @deprecated
279      */
280    virtual void elementTypeInfo
281    (
282        const   XMLCh* const /* typeName */
283        , const XMLCh* const /* typeURI */
284    ) { /* non pure virtual to permit backward compatibility of implementations.  */  };
285    //@}
286
287
288
289protected :
290    // -----------------------------------------------------------------------
291    //  Hidden Constructors
292    // -----------------------------------------------------------------------
293    XMLDocumentHandler()
294    {
295    }
296
297
298private:
299    // -----------------------------------------------------------------------
300    //  Unimplemented constructors and operators
301    // -----------------------------------------------------------------------
302    XMLDocumentHandler(const XMLDocumentHandler&);
303    XMLDocumentHandler& operator=(const XMLDocumentHandler&);
304};
305
306XERCES_CPP_NAMESPACE_END
307
308#endif
Note: See TracBrowser for help on using the repository browser.