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 "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.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;
40 #ifdef RD_SEN_FORCE_LIBXML_SAX_PLUGIN_MIMETYPE
41 _LIT8(KXmlParserMimeType, "text/wsstarlibxml2");
42 _LIT8(KXmlVariant, "wsstarlibxml2");
44 _LIT8(KXmlParserMimeType, "text/xml");
45 _LIT8(KXmlVariant, "libxml2"); // LibXml2 SAX parser
48 // FORWARD DECLARATIONS
49 class MSenContentHandlerClient;
55 * Class extends Symbian XML framework parser functionality
56 * Callers of this class must register some handler which will
57 * then receive XML callback events from underlying Symbian
62 class CSenXmlReader : public CBase, public MContentHandler
64 public: // Constructors and destructor
67 * Standard two-phase constructor.
68 * Creates new parser instance using default
69 * MIME type "text/xml" (KXmlParserMimeType).
71 * @return pointer to a new CSenXmlReader instance.
73 IMPORT_C static CSenXmlReader* NewL();
76 * Standard two-phase constructor.
77 * Creates new parser instance using default
78 * MIME type "text/xml" (KXmlParserMimeType).
80 * @return pointer to a new CSenXmlReader instance
81 * which is left on cleanup stack.
83 IMPORT_C static CSenXmlReader* NewLC();
86 * A constructor with parser feature enabling. Uses default
87 * parser MIME type "text/xml" (KXmlParserMimeType).
89 * @param aParserFeature is typically some enumeration introduced
90 * in Xml::TParserFeature or some other feature introduced in
91 * some XML parser implementation.
93 * KErrArgument if aParserFeature value is negative.
95 IMPORT_C static CSenXmlReader* NewL(TInt aParserFeature);
98 * A constructor with parser feature enabling. Uses default
99 * parser MIME type "text/xml" (KXmlParserMimeType).
100 * @since Series60 3.0
101 * @param aParserMimeType is the XML parser MIME type.
102 * If descriptor is of zero-length, then default
103 * MIME type KXmlParserMimeType is used ("text/xml").
104 * Availability of other MIME types depends on
105 * underlying parser implementation.
106 * @param aParserFeature is typically some enumeration introduced
107 * in Xml::TParserFeature or some other feature introduced in
108 * some XML parser implementation.
110 * KErrArgument if aParserFeature value is negative.
112 IMPORT_C static CSenXmlReader* NewLC(TInt aParserFeature);
115 * A constructor with parser MIME type.
116 * Standard two-phase constructor.
117 * @since Series60 3.0
118 * @param aParserMimeType is the XML parser MIME type.
119 * If descriptor is of zero-length, then default
120 * MIME type KXmlParserMimeType is used ("text/xml").
121 * Availability of other MIME types depends on
122 * underlying parser implementation.
123 * @return pointer to a new CSenXmlReader instance.
125 IMPORT_C static CSenXmlReader* NewL(const TDesC8& aParserMimeType);
128 * A constructor with parser MIME type.
129 * @since Series60 3.0
130 * @param aParserMimeType is the XML parser MIME type.
131 * If descriptor is of zero-length, then default
132 * MIME type KXmlParserMimeType is used ("text/xml").
133 * Availability of other MIME types depends on
134 * underlying parser implementation.
135 * @return pointer to a new CSenXmlReader instance
136 * which is left on cleanup stack.
138 IMPORT_C static CSenXmlReader* NewLC(const TDesC8& aParserMimeType);
141 * A constructor with parser MIME type and parser feature enabling.
142 * @since Series60 3.0
143 * @param aParserFeature is typically some enumeration introduced
144 * in Xml::TParserFeature or some other feature introduced in
145 * some XML parser implementation.
147 * KErrArgument if aParserFeature value is negative.
149 IMPORT_C static CSenXmlReader* NewL(const TDesC8& aParserMimeType,
150 TInt aParserFeature);
153 * A constructor with parser MIME type and parser feature enabling.
154 * @since Series60 3.0
155 * @param aParserMimeType is the XML parser MIME type.
156 * If descriptor is of zero-length, then default
157 * MIME type KXmlParserMimeType is used ("text/xml").
158 * Availability of other MIME types depends on
159 * underlying parser implementation.
160 * @param aParserFeature is typically some enumeration introduced
161 * in Xml::TParserFeature or some other feature introduced in
162 * some XML parser implementation.
164 * KErrArgument if aParserFeature value is negative.
166 IMPORT_C static CSenXmlReader* NewLC(const TDesC8& aParserMimeType,
167 TInt aParserFeature);
172 IMPORT_C virtual ~CSenXmlReader();
177 * Method to allow client to register a content event handler (for XML) for
178 * the current reader.
179 * @since Series60 3.0
180 * @param aContentHandler The new event handler.
182 IMPORT_C virtual void SetContentHandler(
183 MSenContentHandlerClient& aContentHandler);
186 * Method for checking which feature has been enabled in the parser.
187 * @since Series60 3.0
188 * @return the corresponding integer id of the feature
190 IMPORT_C virtual TInt EnabledParserFeature();
193 * @deprecated - use EnabledParserFeature() instead.
195 IMPORT_C virtual TInt ParserFeature();
198 * Method for enabling a parser feature.
199 * @since Series60 3.0
200 * @param aParserFeature is typically some enumeration introduced
201 * in Xml::TParserFeature or some other feature introduced in
202 * some XML parser implementation.
203 * @return KErrNone or some system-wide error code, if an error has
206 TInt SetParserFeature(TInt aParserFeature);
209 * Parse an XML buffer.
210 * @since Series60 3.0
211 * @param aBuff Buffer containing document to parse.
212 * Note that this method will also leave, if an error
213 * is returned from Symbian XML framework. Here are
214 * the corresponding enums, and their respective
215 * error code values (-1000, -999... and up)
216 * (XML-specific errors returned by the XML parser)
217 * [from XmlParserErrors.h]
218 * EXmlParserError = -1000,
219 * EXmlSyntax = 2+EXmlParserError, // -998
220 * EXmlNoElements, // -997
221 * EXmlInvalidToken, // -996
222 * EXmlUnclosedToken, // -995
223 * EXmlPartialChar, // -994
224 * EXmlTagMismatch, // -993
225 * EXmlDuplicateAttribute, // -992
226 * EXmlJunkAfterDocElement, // -991
228 * EXmlUndefinedEntity, // -989
229 * EXmlRecursiveEntity, // -988
230 * EXmlAsyncEntity, // -987
231 * EXmlBadCharRef, // -986
232 * EXmlBinaryEntityRef, // -985
233 * EXmlAttributeExternalEntityRef, // -984
234 * EXmlMisplacedPi, // -983
235 * EXmlUnknownEncoding, // -982
236 * EXmlIncorrectEncoding, // -981
237 * EXmlUnclosedCdata, // -980
238 * EXmlExternalEntityHandling, // -979
239 * EXmlNotStandalone, // -978
240 * EXmlUnexpectedState, // -977
241 * EXmlEntityDeclInPe, // -976
242 * EXmlDtdRequired, // -975
243 * EXmlFeatureLockedWhileParsing // -974
245 IMPORT_C void ParseL(const TDesC8& aBuff);
248 * Parse an XML document.
249 * @since Series60 3.0
250 * @param aRFs An open filesession.
251 * @param aFileToParse Filename of file to parse.
253 IMPORT_C void ParseL(RFs &aRFs, const TDesC& aFileToParse);
255 // Functions from base classes
257 // Callback functions implementing Symbian MContentHandler interface
260 * @since Series60 3.0
262 * KErrSenXmlContentHandlerNotSet if XML content handler
263 * for this XML reader has not been set. This leave can
264 * be avoided calling SetContentHandlerL() method prior
265 * parsing some XML document.
267 virtual void OnStartDocumentL(const RDocumentParameters& aDocParam,
271 * @since Series60 3.0
273 * KErrSenXmlContentHandlerNotSet if XML content handler
274 * for this XML reader has not been set. This leave can
275 * be avoided calling SetContentHandlerL() method prior
276 * parsing some XML document.
278 virtual void OnEndDocumentL(TInt aErrorCode);
281 * @since Series60 3.0
283 * KErrSenXmlContentHandlerNotSet if XML content handler
284 * for this XML reader has not been set. This leave can
285 * be avoided calling SetContentHandlerL() method prior
286 * parsing some XML document.
288 virtual void OnStartElementL(const RTagInfo& aElement,
289 const RAttributeArray& aAttributes,
293 * @since Series60 3.0
295 * KErrSenXmlContentHandlerNotSet if XML content handler
296 * for this XML reader has not been set. This leave can
297 * be avoided calling SetContentHandlerL() method prior
298 * parsing some XML document.
300 virtual void OnEndElementL(const RTagInfo& aElement, TInt aErrorCode);
303 * @since Series60 3.0
304 * @param aBytes is the actual XML data, content in UTF-8 form
305 * @param aErrorCode KErrNone, or some system-wide error code
306 * if an error has occured.
308 virtual void OnContentL(const TDesC8& aBytes, TInt aErrorCode);
311 * @since Series60 3.0
313 * KErrSenXmlContentHandlerNotSet if XML content handler
314 * for this XML reader has not been set. This leave can
315 * be avoided calling SetContentHandlerL() method prior
316 * parsing some XML document.
318 virtual void OnStartPrefixMappingL(const RString& aPrefix,
323 * @since Series60 3.0
325 * KErrSenXmlContentHandlerNotSet if XML content handler
326 * for this XML reader has not been set. This leave can
327 * be avoided calling SetContentHandlerL() method prior
328 * parsing some XML document.
330 virtual void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode);
333 * @since Series60 3.0
335 * KErrSenXmlContentHandlerNotSet if XML content handler
336 * for this XML reader has not been set. This leave can
337 * be avoided calling SetContentHandlerL() method prior
338 * parsing some XML document.
340 virtual void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode);
343 * @since Series60 3.0
345 * KErrSenXmlContentHandlerNotSet if XML content handler
346 * for this XML reader has not been set. This leave can
347 * be avoided calling SetContentHandlerL() method prior
348 * parsing some XML document.
350 virtual void OnSkippedEntityL(const RString& aName, TInt aErrorCode);
353 * @since Series60 3.0
355 * KErrSenXmlContentHandlerNotSet if XML content handler
356 * for this XML reader has not been set. This leave can
357 * be avoided calling SetContentHandlerL() method prior
358 * parsing some XML document.
360 virtual void OnProcessingInstructionL(const TDesC8& aTarget,
365 * OnError is a callback method signalled by Symbian XML
366 * framework. Current implementation of this class issues
367 * a leave in original ParseL() call on any received by
368 * this callback implementation. Used leave code will be
369 * the received error code.
371 * @since Series60 3.0
372 * @param aErrorCode is one of the Symbian XML framework
373 * errors listed in XmlFrameworkErrors.h
377 * If content handler was not set, ParseL will leaves with
378 * KErrSenXmlContentHandlerNotSet.
380 virtual void OnError(TInt aErrorCode);
383 * This method obtains the interface matching the specified UID.
384 * @since Series60 3.0
385 * @param aUid the UID identifying the required interface.
386 * @return NULL if no interface matching the UID is found or
387 * if content handler was not set. Otherwise,
388 * returns pointer to the interface.
390 virtual TAny* GetExtendedInterface(const TInt32 aUid);
397 IMPORT_C CSenXmlReader(TInt aParserFeature);
400 * Symbian 2nd phase constructor.
401 * @param aParserMimeType sets the MIME type of
404 void ConstructL(const TDesC8& aParserMimeType);
409 * This method re-initializes encapsulated CParser class instance.
410 * @since Series60 3.0
412 void RecreateParserL();
415 static void CleanupParser(TAny* apReader);
420 // Owned instance of Symbian XML framework (default) XML parser
422 // Not owned pointer to XML content handler.
423 MSenContentHandlerClient* iContentHandler;
424 // Owned pointer to XML namespace prefix strings
425 CDesC8Array* ipNsPrefixes;
426 // Owned pointer to XML namespace URI strings
427 CDesC8Array* ipNsUris;
428 // Owned string pool for XML attribute handling.
429 RStringPool iStringPool;
430 // Integer indicating currently enabled features
431 TInt iEnabledFeature;
434 #endif // SEN_XMLREADER_H