2 * Copyright (c) 2008 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.
22 #ifndef XMLENGDOMPARSER_H
23 #define XMLENGDOMPARSER_H
27 class RXmlEngDOMImplementation;
28 class RXmlEngDocument;
31 This class implements methods for parsing XML data. XML data may be parsed
32 from a chunk, file, or memory buffer.
34 Sample code for parsing from buffer:
36 RXmlEngDOMImplementation domImpl;
37 domImpl.OpenL(); // opening DOM implementation object
38 RXmlEngDOMParser parser;
39 parser.Open( domImpl ); // opening parser object
41 iDoc =parser.ParseL( *aInput ); // parsing aInput - buffer
42 iDoc.Close(); // closing all opened objects
47 Sample code for parsing from file:
49 RXmlEngDOMImplementation domImpl;
50 domImpl.OpenL(); // opening DOM implementation object
51 RXmlEngDOMParser parser;
52 parser.Open( domImpl ); // opening parser object
54 iDoc =parser.ParseFileL( aFileName ); // parsing from file
55 iDoc.Close(); // closing all openend objects
60 class RXmlEngDOMParser
63 /** Default constructor */
64 IMPORT_C RXmlEngDOMParser();
67 Opens the parser. The RXmlEngDOMImplementation object passed as an
68 argument may be used by multiple RXmlEngDOMParser objects.
70 @param aDOMImpl DOM implementation object previously opened without error.
71 @return KErrNone if successful, system wide error code otherwise
73 IMPORT_C TInt Open(RXmlEngDOMImplementation& aDOMImpl);
75 /** Closes the parser. */
76 IMPORT_C void Close();
79 Parses a chunk of XML data from a memory buffer and builds an internal DOM
80 tree. The DOM tree can be accessed by calling FinishL() to obtain a
84 @param aBuffer XML data buffer
85 @see GetLastParsingError()
86 @leave KXmlEngErrParsing Parsing error
87 @leave KXmlEngErrWrongUseOfAPI OpenL() not previously called
88 @leave - One of the system-wide error codes
90 IMPORT_C void ParseChunkL(const TDesC8& aBuffer);
93 Creates a document from chunks of data previously parsed by ParseChunkL().
94 Should be called after parsing all chunks. Ownership of the returned
95 RXmlEngDocument object is transferred to the caller of the method.
96 RXmlEngDocument::Close() must be called when the document is no longer
100 @return The created document
101 @see GetLastParsingError()
102 @leave KXmlEngErrParsing Parsing error
103 @leave KXmlEngErrWrongUseOfAPI OpenL() or ParseChunkL() not previously
105 @leave - One of the system-wide error codes
107 IMPORT_C RXmlEngDocument FinishL();
110 Parses XML file and builds a DOM RXmlEngDocument. Ownership of the
111 returned RXmlEngDocument object is transferred to the caller of the method.
112 RXmlEngDocument::Close() must be called when the document is no longer
115 @param aRFs Open file server session
116 @param aFileName File name
117 @param aChunkSize The number of bytes to parse from the file at a time, or 0
118 if the whole file should be parsed at once.
119 @return The created document
120 @see GetLastParsingError()
121 @leave KXmlEngErrParsing Parsing error
122 @leave KXmlEngErrWrongUseOfAPI OpenL() not previously called
123 @leave - One of the system-wide error codes
125 IMPORT_C RXmlEngDocument ParseFileL(RFs &aRFs, const TDesC& aFileName, TUint aChunkSize = 0);
128 Parses XML file and builds a DOM RXmlEngDocument. Ownership of the
129 returned RXmlEngDocument object is transferred to the caller of the method.
130 RXmlEngDocument::Close() must be called when the document is no longer
133 @param aFileName File name
134 @param aChunkSize The number of bytes to parse from the file at a time, or 0
135 if the whole file should be parsed at once.
136 @return The created document
137 @see GetLastParsingError()
138 @leave KXmlEngErrParsing Parsing error
139 @leave KXmlEngErrWrongUseOfAPI OpenL() not previously called
140 @leave - One of the system-wide error codes
142 IMPORT_C RXmlEngDocument ParseFileL(const TDesC& aFileName, TUint aChunkSize = 0);
145 Parses XML data from a memory buffer that holds the entire XML structure
146 and builds a DOM RXmlEngDocument. Ownership of the returned
147 RXmlEngDocument object is transferred to the caller of the method.
148 RXmlEngDocument::Close() must be called when the document is no longer
152 @param aBuffer XML data buffer
153 @return The created document
154 @see GetLastParsingError()
155 @leave KXmlEngErrParsing Parsing error
156 @leave KXmlEngErrWrongUseOfAPI OpenL() not previously called
157 @leave - One of the system-wide error codes
159 IMPORT_C RXmlEngDocument ParseL(const TDesC8& aBuffer);
162 Return last parsing error code. Error codes are positive numbers.
164 @return The last error returned by the parser or KErrNone if none
166 IMPORT_C TInt GetLastParsingError();
169 RXmlEngDocument ParseFileWithoutChunksL(RFs& aRFs, const TDesC& aFileName);
175 RXmlEngDOMImplementation* iImpl;
178 #endif /* XMLENGDOMPARSER_H */