2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Class extends Symbian XML framework parser functionality
25 #ifndef SEN_XMLREADER_H
26 #define SEN_XMLREADER_H
29 #include <Xml/Parser.h>
30 #include <Xml/ParserFeature.h> // for TParserFeature enumeration
31 #include <Xml/ContentHandler.h>
37 const TInt KSenDefaultParserFeature = (TInt)EReportNamespaceMapping;
41 // FORWARD DECLARATIONS
42 class MSenContentHandlerClient;
48 * Class extends Symbian XML framework parser functionality
49 * Callers of this class must register some handler which will
50 * then receive XML callback events from underlying Symbian
55 class CSenXmlReader : public CBase, public MContentHandler
57 public: // Constructors and destructor
60 * Standard two-phase constructor.
61 * Creates new parser instance using default
62 * MIME type "text/xml" (KXmlParserMimeType).
64 * @return pointer to a new CSenXmlReader instance.
66 IMPORT_C static CSenXmlReader* NewL();
69 * Standard two-phase constructor.
70 * Creates new parser instance using default
71 * MIME type "text/xml" (KXmlParserMimeType).
73 * @return pointer to a new CSenXmlReader instance
74 * which is left on cleanup stack.
76 IMPORT_C static CSenXmlReader* NewLC();
79 * A constructor with parser feature enabling. Uses default
80 * parser MIME type "text/xml" (KXmlParserMimeType).
82 * @param aParserFeature is typically some enumeration introduced
83 * in Xml::TParserFeature or some other feature introduced in
84 * some XML parser implementation.
86 * KErrArgument if aParserFeature value is negative.
88 IMPORT_C static CSenXmlReader* NewL(TInt aParserFeature);
91 * A constructor with parser feature enabling. Uses default
92 * parser MIME type "text/xml" (KXmlParserMimeType).
94 * @param aParserMimeType is the XML parser MIME type.
95 * If descriptor is of zero-length, then default
96 * MIME type KXmlParserMimeType is used ("text/xml").
97 * Availability of other MIME types depends on
98 * underlying parser implementation.
99 * @param aParserFeature is typically some enumeration introduced
100 * in Xml::TParserFeature or some other feature introduced in
101 * some XML parser implementation.
103 * KErrArgument if aParserFeature value is negative.
105 IMPORT_C static CSenXmlReader* NewLC(TInt aParserFeature);
108 * A constructor with parser MIME type.
109 * Standard two-phase constructor.
110 * @since Series60 3.0
111 * @param aParserMimeType is the XML parser MIME type.
112 * If descriptor is of zero-length, then default
113 * MIME type KXmlParserMimeType is used ("text/xml").
114 * Availability of other MIME types depends on
115 * underlying parser implementation.
116 * @return pointer to a new CSenXmlReader instance.
118 IMPORT_C static CSenXmlReader* NewL(const TDesC8& aParserMimeType);
121 * A constructor with parser MIME type.
122 * @since Series60 3.0
123 * @param aParserMimeType is the XML parser MIME type.
124 * If descriptor is of zero-length, then default
125 * MIME type KXmlParserMimeType is used ("text/xml").
126 * Availability of other MIME types depends on
127 * underlying parser implementation.
128 * @return pointer to a new CSenXmlReader instance
129 * which is left on cleanup stack.
131 IMPORT_C static CSenXmlReader* NewLC(const TDesC8& aParserMimeType);
134 * A constructor with parser MIME type and parser feature enabling.
135 * @since Series60 3.0
136 * @param aParserFeature is typically some enumeration introduced
137 * in Xml::TParserFeature or some other feature introduced in
138 * some XML parser implementation.
140 * KErrArgument if aParserFeature value is negative.
142 IMPORT_C static CSenXmlReader* NewL(const TDesC8& aParserMimeType,
143 TInt aParserFeature);
146 * A constructor with parser MIME type and parser feature enabling.
147 * @since Series60 3.0
148 * @param aParserMimeType is the XML parser MIME type.
149 * If descriptor is of zero-length, then default
150 * MIME type KXmlParserMimeType is used ("text/xml").
151 * Availability of other MIME types depends on
152 * underlying parser implementation.
153 * @param aParserFeature is typically some enumeration introduced
154 * in Xml::TParserFeature or some other feature introduced in
155 * some XML parser implementation.
157 * KErrArgument if aParserFeature value is negative.
159 IMPORT_C static CSenXmlReader* NewLC(const TDesC8& aParserMimeType,
160 TInt aParserFeature);
165 IMPORT_C virtual ~CSenXmlReader();
170 * Method to allow client to register a content event handler (for XML) for
171 * the current reader.
172 * @since Series60 3.0
173 * @param aContentHandler The new event handler.
175 IMPORT_C virtual void SetContentHandler(
176 MSenContentHandlerClient& aContentHandler);
179 * Method for checking which feature has been enabled in the parser.
180 * @since Series60 3.0
181 * @return the corresponding integer id of the feature
183 IMPORT_C virtual TInt EnabledParserFeature();
186 * @deprecated - use EnabledParserFeature() instead.
188 IMPORT_C virtual TInt ParserFeature();
191 * Method for enabling a parser feature.
192 * @since Series60 3.0
193 * @param aParserFeature is typically some enumeration introduced
194 * in Xml::TParserFeature or some other feature introduced in
195 * some XML parser implementation.
196 * @return KErrNone or some system-wide error code, if an error has
199 TInt SetParserFeature(TInt aParserFeature);
202 * Parse an XML buffer.
203 * @since Series60 3.0
204 * @param aBuff Buffer containing document to parse.
205 * Note that this method will also leave, if an error
206 * is returned from Symbian XML framework. Here are
207 * the corresponding enums, and their respective
208 * error code values (-1000, -999... and up)
209 * (XML-specific errors returned by the XML parser)
210 * [from XmlParserErrors.h]
211 * EXmlParserError = -1000,
212 * EXmlSyntax = 2+EXmlParserError, // -998
213 * EXmlNoElements, // -997
214 * EXmlInvalidToken, // -996
215 * EXmlUnclosedToken, // -995
216 * EXmlPartialChar, // -994
217 * EXmlTagMismatch, // -993
218 * EXmlDuplicateAttribute, // -992
219 * EXmlJunkAfterDocElement, // -991
221 * EXmlUndefinedEntity, // -989
222 * EXmlRecursiveEntity, // -988
223 * EXmlAsyncEntity, // -987
224 * EXmlBadCharRef, // -986
225 * EXmlBinaryEntityRef, // -985
226 * EXmlAttributeExternalEntityRef, // -984
227 * EXmlMisplacedPi, // -983
228 * EXmlUnknownEncoding, // -982
229 * EXmlIncorrectEncoding, // -981
230 * EXmlUnclosedCdata, // -980
231 * EXmlExternalEntityHandling, // -979
232 * EXmlNotStandalone, // -978
233 * EXmlUnexpectedState, // -977
234 * EXmlEntityDeclInPe, // -976
235 * EXmlDtdRequired, // -975
236 * EXmlFeatureLockedWhileParsing // -974
238 IMPORT_C void ParseL(const TDesC8& aBuff);
241 * Parse an XML document.
242 * @since Series60 3.0
243 * @param aRFs An open filesession.
244 * @param aFileToParse Filename of file to parse.
246 IMPORT_C void ParseL(RFs &aRFs, const TDesC& aFileToParse);
248 // Functions from base classes
250 // Callback functions implementing Symbian MContentHandler interface
253 * @since Series60 3.0
255 * KErrSenXmlContentHandlerNotSet if XML content handler
256 * for this XML reader has not been set. This leave can
257 * be avoided calling SetContentHandlerL() method prior
258 * parsing some XML document.
260 virtual void OnStartDocumentL(const RDocumentParameters& aDocParam,
264 * @since Series60 3.0
266 * KErrSenXmlContentHandlerNotSet if XML content handler
267 * for this XML reader has not been set. This leave can
268 * be avoided calling SetContentHandlerL() method prior
269 * parsing some XML document.
271 virtual void OnEndDocumentL(TInt aErrorCode);
274 * @since Series60 3.0
276 * KErrSenXmlContentHandlerNotSet if XML content handler
277 * for this XML reader has not been set. This leave can
278 * be avoided calling SetContentHandlerL() method prior
279 * parsing some XML document.
281 virtual void OnStartElementL(const RTagInfo& aElement,
282 const RAttributeArray& aAttributes,
286 * @since Series60 3.0
288 * KErrSenXmlContentHandlerNotSet if XML content handler
289 * for this XML reader has not been set. This leave can
290 * be avoided calling SetContentHandlerL() method prior
291 * parsing some XML document.
293 virtual void OnEndElementL(const RTagInfo& aElement, TInt aErrorCode);
296 * @since Series60 3.0
297 * @param aBytes is the actual XML data, content in UTF-8 form
298 * @param aErrorCode KErrNone, or some system-wide error code
299 * if an error has occured.
301 virtual void OnContentL(const TDesC8& aBytes, TInt aErrorCode);
304 * @since Series60 3.0
306 * KErrSenXmlContentHandlerNotSet if XML content handler
307 * for this XML reader has not been set. This leave can
308 * be avoided calling SetContentHandlerL() method prior
309 * parsing some XML document.
311 virtual void OnStartPrefixMappingL(const RString& aPrefix,
316 * @since Series60 3.0
318 * KErrSenXmlContentHandlerNotSet if XML content handler
319 * for this XML reader has not been set. This leave can
320 * be avoided calling SetContentHandlerL() method prior
321 * parsing some XML document.
323 virtual void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode);
326 * @since Series60 3.0
328 * KErrSenXmlContentHandlerNotSet if XML content handler
329 * for this XML reader has not been set. This leave can
330 * be avoided calling SetContentHandlerL() method prior
331 * parsing some XML document.
333 virtual void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode);
336 * @since Series60 3.0
338 * KErrSenXmlContentHandlerNotSet if XML content handler
339 * for this XML reader has not been set. This leave can
340 * be avoided calling SetContentHandlerL() method prior
341 * parsing some XML document.
343 virtual void OnSkippedEntityL(const RString& aName, TInt aErrorCode);
346 * @since Series60 3.0
348 * KErrSenXmlContentHandlerNotSet if XML content handler
349 * for this XML reader has not been set. This leave can
350 * be avoided calling SetContentHandlerL() method prior
351 * parsing some XML document.
353 virtual void OnProcessingInstructionL(const TDesC8& aTarget,
358 * OnError is a callback method signalled by Symbian XML
359 * framework. Current implementation of this class issues
360 * a leave in original ParseL() call on any received by
361 * this callback implementation. Used leave code will be
362 * the received error code.
364 * @since Series60 3.0
365 * @param aErrorCode is one of the Symbian XML framework
366 * errors listed in XmlFrameworkErrors.h
370 * If content handler was not set, ParseL will leaves with
371 * KErrSenXmlContentHandlerNotSet.
373 virtual void OnError(TInt aErrorCode);
376 * This method obtains the interface matching the specified UID.
377 * @since Series60 3.0
378 * @param aUid the UID identifying the required interface.
379 * @return NULL if no interface matching the UID is found or
380 * if content handler was not set. Otherwise,
381 * returns pointer to the interface.
383 virtual TAny* GetExtendedInterface(const TInt32 aUid);
390 IMPORT_C CSenXmlReader(TInt aParserFeature);
393 * Symbian 2nd phase constructor.
394 * @param aParserMimeType sets the MIME type of
397 void ConstructL(const TDesC8& aParserMimeType);
402 * This method re-initializes encapsulated CParser class instance.
403 * @since Series60 3.0
405 void RecreateParserL();
408 static void CleanupParser(TAny* apReader);
413 // Owned instance of Symbian XML framework (default) XML parser
415 // Not owned pointer to XML content handler.
416 MSenContentHandlerClient* iContentHandler;
417 // Owned pointer to XML namespace prefix strings
418 CDesC8Array* ipNsPrefixes;
419 // Owned pointer to XML namespace URI strings
420 CDesC8Array* ipNsUris;
421 // Owned string pool for XML attribute handling.
422 RStringPool iStringPool;
423 // Integer indicating currently enabled features
424 TInt iEnabledFeature;
427 #endif // SEN_XMLREADER_H