1 | // |
---|
2 | // XMLReader.h |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/XML/include/Poco/SAX/XMLReader.h#2 $ |
---|
5 | // |
---|
6 | // Library: XML |
---|
7 | // Package: SAX |
---|
8 | // Module: SAX |
---|
9 | // |
---|
10 | // SAX2 XMLReader 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_XMLReader_INCLUDED |
---|
40 | #define SAX_XMLReader_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 EntityResolver; |
---|
52 | class DTDHandler; |
---|
53 | class ContentHandler; |
---|
54 | class ErrorHandler; |
---|
55 | class InputSource; |
---|
56 | class LexicalHandler; |
---|
57 | class NamespaceHandler; |
---|
58 | |
---|
59 | |
---|
60 | class XML_API XMLReader |
---|
61 | /// Interface for reading an XML document using callbacks. |
---|
62 | /// XMLReader is the interface that an XML parser's SAX2 driver must |
---|
63 | /// implement. This interface allows an application to set and |
---|
64 | /// query features and properties in the parser, to register event handlers |
---|
65 | /// for document processing, and to initiate a document parse. |
---|
66 | /// All SAX interfaces are assumed to be synchronous: the parse methods must not |
---|
67 | /// return until parsing is complete, and readers |
---|
68 | /// must wait for an event-handler callback to return before reporting the next event. |
---|
69 | { |
---|
70 | public: |
---|
71 | virtual void setEntityResolver(EntityResolver* pResolver) = 0; |
---|
72 | /// Allow an application to register an entity resolver. |
---|
73 | /// |
---|
74 | /// If the application does not register an entity resolver, the |
---|
75 | /// XMLReader will perform its own default resolution. |
---|
76 | /// |
---|
77 | /// Applications may register a new or different resolver in the middle of a |
---|
78 | /// parse, and the SAX parser must begin using the new resolver immediately. |
---|
79 | |
---|
80 | virtual EntityResolver* getEntityResolver() const = 0; |
---|
81 | /// Return the current entity resolver. |
---|
82 | |
---|
83 | virtual void setDTDHandler(DTDHandler* pDTDHandler) = 0; |
---|
84 | /// Allow an application to register a DTD event handler. |
---|
85 | /// |
---|
86 | /// If the application does not register a DTD handler, all DTD events reported by |
---|
87 | /// the SAX parser will be silently ignored. |
---|
88 | /// |
---|
89 | /// Applications may register a new or different handler in the middle of a parse, |
---|
90 | /// and the SAX parser must begin using the new handler immediately. |
---|
91 | |
---|
92 | virtual DTDHandler* getDTDHandler() const = 0; |
---|
93 | /// Return the current DTD handler. |
---|
94 | |
---|
95 | virtual void setContentHandler(ContentHandler* pContentHandler) = 0; |
---|
96 | /// Allow an application to register a content event handler. |
---|
97 | /// |
---|
98 | /// If the application does not register a content handler, all content events |
---|
99 | /// reported by the SAX parser will be silently ignored. |
---|
100 | /// |
---|
101 | /// Applications may register a new or different handler in the middle of a parse, |
---|
102 | /// and the SAX parser must begin using the new handler immediately. |
---|
103 | |
---|
104 | virtual ContentHandler* getContentHandler() const = 0; |
---|
105 | /// Return the current content handler. |
---|
106 | |
---|
107 | virtual void setErrorHandler(ErrorHandler* pErrorHandler) = 0; |
---|
108 | /// Allow an application to register an error event handler. |
---|
109 | /// |
---|
110 | /// If the application does not register an error handler, all error events reported by |
---|
111 | /// the SAX parser will be silently ignored; however, normal processing may not continue. |
---|
112 | /// It is highly recommended that all SAX applications implement an error handler to avoid |
---|
113 | /// unexpected bugs. |
---|
114 | /// |
---|
115 | /// Applications may register a new or different handler in the middle of a parse, and the |
---|
116 | /// SAX parser must begin using the new handler immediately. |
---|
117 | |
---|
118 | virtual ErrorHandler* getErrorHandler() const = 0; |
---|
119 | /// Return the current error handler. |
---|
120 | |
---|
121 | virtual void setFeature(const XMLString& featureId, bool state) = 0; |
---|
122 | /// Set the state of a feature. |
---|
123 | /// |
---|
124 | /// The feature name is any fully-qualified URI. It is possible for an XMLReader to |
---|
125 | /// expose a feature value but to be unable to change the current value. Some feature |
---|
126 | /// values may be immutable or mutable only in specific contexts, such as before, during, |
---|
127 | /// or after a parse. |
---|
128 | /// |
---|
129 | /// All XMLReaders are required to support setting http://xml.org/sax/features/namespaces |
---|
130 | /// to true and http://xml.org/sax/features/namespace-prefixes to false. |
---|
131 | |
---|
132 | virtual bool getFeature(const XMLString& featureId) const = 0; |
---|
133 | /// Look up the value of a feature. |
---|
134 | /// |
---|
135 | /// The feature name is any fully-qualified URI. It is possible for an XMLReader |
---|
136 | /// to recognize a feature name but temporarily be unable to return its value. |
---|
137 | /// Some feature values may be available only in specific contexts, such as before, |
---|
138 | /// during, or after a parse. Also, some feature values may not be programmatically |
---|
139 | /// accessible. (In the case of an adapter for SAX1 Parser, there is no |
---|
140 | /// implementation-independent way to expose whether the underlying parser is performing |
---|
141 | /// validation, expanding external entities, and so forth.) |
---|
142 | /// |
---|
143 | /// All XMLReaders are required to recognize the |
---|
144 | /// http://xml.org/sax/features/namespaces and the |
---|
145 | /// http://xml.org/sax/features/namespace-prefixes feature names. |
---|
146 | /// Implementors are free (and encouraged) to invent their own features, |
---|
147 | /// using names built on their own URIs. |
---|
148 | |
---|
149 | virtual void setProperty(const XMLString& propertyId, const XMLString& value) = 0; |
---|
150 | /// Set the value of a property. |
---|
151 | /// |
---|
152 | /// The property name is any fully-qualified URI. It is possible for an XMLReader |
---|
153 | /// to recognize a property name but to be unable to change the current value. |
---|
154 | /// Some property values may be immutable or mutable only in specific contexts, |
---|
155 | /// such as before, during, or after a parse. |
---|
156 | /// |
---|
157 | /// XMLReaders are not required to recognize setting any specific property names, though a |
---|
158 | /// core set is defined by SAX2. |
---|
159 | /// |
---|
160 | /// This method is also the standard mechanism for setting extended handlers. |
---|
161 | |
---|
162 | virtual void setProperty(const XMLString& propertyId, void* value) = 0; |
---|
163 | /// Set the value of a property. |
---|
164 | /// See also setProperty(const XMLString&, const XMLString&). |
---|
165 | |
---|
166 | virtual void* getProperty(const XMLString& propertyId) const = 0; |
---|
167 | /// Look up the value of a property. |
---|
168 | /// String values are returned as XMLChar* |
---|
169 | /// The property name is any fully-qualified URI. It is possible for an XMLReader to |
---|
170 | /// recognize a property name but temporarily be unable to return its value. Some property |
---|
171 | /// values may be available only in specific contexts, such as before, during, or after a parse. |
---|
172 | /// |
---|
173 | /// XMLReaders are not required to recognize any specific property names, though an initial |
---|
174 | /// core set is documented for SAX2. |
---|
175 | /// |
---|
176 | /// Implementors are free (and encouraged) to invent their own properties, using names |
---|
177 | /// built on their own URIs. |
---|
178 | |
---|
179 | virtual void parse(InputSource* pSource) = 0; |
---|
180 | /// Parse an XML document. |
---|
181 | /// |
---|
182 | /// The application can use this method to instruct the XML reader to begin parsing an |
---|
183 | /// XML document from any valid input source (a character stream, a byte stream, or a URI). |
---|
184 | /// |
---|
185 | /// Applications may not invoke this method while a parse is in progress (they should create |
---|
186 | /// a new XMLReader instead for each nested XML document). Once a parse is complete, an |
---|
187 | /// application may reuse the same XMLReader object, possibly with a different input source. |
---|
188 | /// Configuration of the XMLReader object (such as handler bindings and values established for |
---|
189 | /// feature flags and properties) is unchanged by completion of a parse, unless the definition of that |
---|
190 | /// aspect of the configuration explicitly specifies other behavior. (For example, feature flags or |
---|
191 | /// properties exposing characteristics of the document being parsed.) |
---|
192 | /// |
---|
193 | /// During the parse, the XMLReader will provide information about the XML document through the registered |
---|
194 | /// event handlers. |
---|
195 | /// |
---|
196 | /// This method is synchronous: it will not return until parsing has ended. If a client application |
---|
197 | /// wants to terminate parsing early, it should throw an exception. |
---|
198 | |
---|
199 | virtual void parse(const XMLString& systemId) = 0; |
---|
200 | /// Parse an XML document from a system identifier. |
---|
201 | /// See also parse(InputSource*). |
---|
202 | |
---|
203 | virtual void parseMemoryNP(const char* xml, std::size_t size) = 0; |
---|
204 | /// Parse an XML document from memory. |
---|
205 | /// See also parse(InputSource*). |
---|
206 | |
---|
207 | // SAX Features |
---|
208 | static const XMLString FEATURE_VALIDATION; |
---|
209 | static const XMLString FEATURE_NAMESPACES; |
---|
210 | static const XMLString FEATURE_NAMESPACE_PREFIXES; |
---|
211 | static const XMLString FEATURE_EXTERNAL_GENERAL_ENTITIES; |
---|
212 | static const XMLString FEATURE_EXTERNAL_PARAMETER_ENTITIES; |
---|
213 | static const XMLString FEATURE_STRING_INTERNING; |
---|
214 | |
---|
215 | // SAX Properties |
---|
216 | static const XMLString PROPERTY_DECLARATION_HANDLER; |
---|
217 | static const XMLString PROPERTY_LEXICAL_HANDLER; |
---|
218 | |
---|
219 | protected: |
---|
220 | virtual ~XMLReader(); |
---|
221 | }; |
---|
222 | |
---|
223 | |
---|
224 | } } // namespace Poco::XML |
---|
225 | |
---|
226 | |
---|
227 | #endif // SAX_XMLReader_INCLUDED |
---|