|
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
2 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
3 <head> |
|
4 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
|
5 <title>TB9.2 Example Applications: examples/SysLibs/XmlExample/xmlexample.cpp Source File</title> |
|
6 <link href="tabs.css" rel="stylesheet" type="text/css"/> |
|
7 <link href="doxygen.css" rel="stylesheet" type="text/css"/> |
|
8 </head> |
|
9 <body> |
|
10 <!-- Generated by Doxygen 1.6.2 --> |
|
11 <h1>examples/SysLibs/XmlExample/xmlexample.cpp</h1><a href="xmlexample_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).</span> |
|
12 <a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span> |
|
13 <a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span> |
|
14 <a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span> |
|
15 <a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span> |
|
16 <a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span> |
|
17 <a name="l00007"></a>00007 <span class="comment">//</span> |
|
18 <a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span> |
|
19 <a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span> |
|
20 <a name="l00010"></a>00010 <span class="comment">//</span> |
|
21 <a name="l00011"></a>00011 <span class="comment">// Contributors:</span> |
|
22 <a name="l00012"></a>00012 <span class="comment">//</span> |
|
23 <a name="l00013"></a>00013 <span class="comment">// Description:</span> |
|
24 <a name="l00014"></a>00014 <span class="comment">// This example program demonstrates the use of XML Framework APIs. </span> |
|
25 <a name="l00015"></a>00015 <span class="comment">// The code implements all the functions of MContentHandler class.</span> |
|
26 <a name="l00016"></a>00016 <span class="comment">// The example parses the XML file and WBXML file present in the specified path. To know how to </span> |
|
27 <a name="l00017"></a>00017 <span class="comment">// write an XML file you can refer to this URL http://www.w3schools.com/xml/.</span> |
|
28 <a name="l00018"></a>00018 <span class="comment">//</span> |
|
29 <a name="l00019"></a>00019 |
|
30 <a name="l00020"></a>00020 |
|
31 <a name="l00021"></a>00021 |
|
32 <a name="l00025"></a>00025 <span class="preprocessor">#include "xmlexample.h"</span> |
|
33 <a name="l00026"></a>00026 <span class="preprocessor">#include <xml/documentparameters.h></span> |
|
34 <a name="l00027"></a>00027 <span class="preprocessor">#include <xml/parserfeature.h></span> |
|
35 <a name="l00028"></a>00028 <span class="preprocessor">#include <xml/matchdata.h></span> |
|
36 <a name="l00029"></a>00029 <span class="preprocessor">#include <e32cons.h></span> |
|
37 <a name="l00030"></a>00030 |
|
38 <a name="l00031"></a>00031 <span class="keyword">using namespace </span>Xml; |
|
39 <a name="l00032"></a>00032 |
|
40 <a name="l00033"></a>00033 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTitle, <span class="stringliteral">"XML example"</span>); |
|
41 <a name="l00034"></a>00034 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KStartKey, <span class="stringliteral">"\nThe example parses the given XML and WBXML files. Press any key to start\n"</span>); |
|
42 <a name="l00035"></a>00035 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPressAKey,<span class="stringliteral">"\nPress any key to continue \n"</span>); |
|
43 <a name="l00036"></a>00036 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KExit,<span class="stringliteral">"\n Press any key to exit the application \n"</span>); |
|
44 <a name="l00037"></a>00037 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KParsingXml,<span class="stringliteral">"\nParsing the XML file"</span>); |
|
45 <a name="l00038"></a>00038 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KParsingWbXml,<span class="stringliteral">"\nParsing the WBXML file"</span>); |
|
46 <a name="l00039"></a>00039 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KParsingMatch,<span class="stringliteral">"\nParsing the XML file using match data criteria"</span>); |
|
47 <a name="l00040"></a>00040 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KError,<span class="stringliteral">"\n Could not open the XML file. Please check if the file exists."</span>); |
|
48 <a name="l00041"></a>00041 |
|
49 <a name="l00042"></a>00042 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnStartDoc,<span class="stringliteral">"\n<!-- CXmlExample::OnStartDocumentL -->\n"</span>); |
|
50 <a name="l00043"></a>00043 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnEndDoc,<span class="stringliteral">"\n<!-- CXmlExample::OnEndDocumentL -->\n"</span>); |
|
51 <a name="l00044"></a>00044 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnContent,<span class="stringliteral">"<!-- CXmlExample::OnContentL -->"</span>); |
|
52 <a name="l00045"></a>00045 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnProcInstrn,<span class="stringliteral">"\n<!-- CXmlExample::OnProcessingInstructionL -->\n"</span>); |
|
53 <a name="l00046"></a>00046 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnError,<span class="stringliteral">"CXmlExample::OnError - ERROR: code=%d\n"</span>); |
|
54 <a name="l00047"></a>00047 |
|
55 <a name="l00048"></a>00048 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KVersion,<span class="stringliteral">"<?xml version=\"1.0\" encoding=\"%S\"?>\n"</span>); |
|
56 <a name="l00049"></a>00049 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KStartElement,<span class="stringliteral">"\nStart of element: <%S>\n"</span>); |
|
57 <a name="l00050"></a>00050 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KEndElement,<span class="stringliteral">"\nEnd of element: </%S>\n"</span>); |
|
58 <a name="l00051"></a>00051 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KContent,<span class="stringliteral">"%S\n"</span>); |
|
59 <a name="l00052"></a>00052 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KAttrib,<span class="stringliteral">"The attribute of element <%S>=\"%S\""</span>); |
|
60 <a name="l00053"></a>00053 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KProcInstrn,<span class="stringliteral">"<?%S %S?>\n"</span>); |
|
61 <a name="l00054"></a>00054 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnSkipped, <span class="stringliteral">"Found skipped entity %S"</span>); |
|
62 <a name="l00055"></a>00055 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KNameSpaceRep,<span class="stringliteral">"\nNamespace mapping reporting enabled\n "</span>); |
|
63 <a name="l00056"></a>00056 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPrefixMap, <span class="stringliteral">"\nThe prefix is %S and URI is %S\n"</span>); |
|
64 <a name="l00057"></a>00057 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPrefixEnd, <span class="stringliteral">"End of prefix URI mapping %S\n"</span>); |
|
65 <a name="l00058"></a>00058 |
|
66 <a name="l00059"></a>00059 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KSimpleXmlFile, <span class="stringliteral">"z:\\private\\E80000AE\\xmlexample.xml"</span>); |
|
67 <a name="l00060"></a>00060 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KSimpleWbXmlFile, <span class="stringliteral">"z:\\private\\E80000AE\\xmlexample.wbxml"</span>); |
|
68 <a name="l00061"></a>00061 _LIT8(KXmlMimeType, <span class="stringliteral">"text/xml"</span>); |
|
69 <a name="l00062"></a>00062 _LIT8(KWbxmlMimeType, <span class="stringliteral">"text/wbxml"</span>); |
|
70 <a name="l00063"></a>00063 |
|
71 <a name="l00068"></a><a class="code" href="class_c_xml_example.html#a9c72dee1761244c6964c76473995eba6">00068</a> <a class="code" href="class_c_xml_example.html">CXmlExample</a>* <a class="code" href="class_c_xml_example.html#a9c72dee1761244c6964c76473995eba6">CXmlExample::NewL</a>() |
|
72 <a name="l00069"></a>00069 { |
|
73 <a name="l00070"></a>00070 <a class="code" href="class_c_xml_example.html">CXmlExample</a>* <span class="keyword">self</span> = <span class="keyword">new</span> (ELeave) <a class="code" href="class_c_xml_example.html">CXmlExample</a>(); |
|
74 <a name="l00071"></a>00071 CleanupStack::PushL(<span class="keyword">self</span>); |
|
75 <a name="l00072"></a>00072 <span class="keyword">self</span>->ConstructL(); |
|
76 <a name="l00073"></a>00073 CleanupStack::Pop(); |
|
77 <a name="l00074"></a>00074 <span class="keywordflow">return</span> <span class="keyword">self</span>; |
|
78 <a name="l00075"></a>00075 } |
|
79 <a name="l00076"></a>00076 |
|
80 <a name="l00077"></a>00077 CXmlExample::CXmlExample() |
|
81 <a name="l00078"></a>00078 :iError(KErrNone) |
|
82 <a name="l00079"></a>00079 { |
|
83 <a name="l00080"></a>00080 } |
|
84 <a name="l00081"></a>00081 |
|
85 <a name="l00082"></a>00082 <span class="keywordtype">void</span> CXmlExample::ConstructL() |
|
86 <a name="l00083"></a>00083 { |
|
87 <a name="l00084"></a>00084 iConsole = <a class="code" href="class_c_xml_example.html#a9c72dee1761244c6964c76473995eba6">Console::NewL</a>(KTitle,TSize(KConsFullScreen,KConsFullScreen)); |
|
88 <a name="l00085"></a>00085 iConsole->Printf ( KStartKey); |
|
89 <a name="l00086"></a>00086 iConsole->Getch (); |
|
90 <a name="l00087"></a>00087 } |
|
91 <a name="l00088"></a>00088 |
|
92 <a name="l00092"></a><a class="code" href="class_c_xml_example.html#a0d8f9e8f410478bbbb83dbf831d9591f">00092</a> <a class="code" href="class_c_xml_example.html#a0d8f9e8f410478bbbb83dbf831d9591f">CXmlExample::~CXmlExample</a>() |
|
93 <a name="l00093"></a>00093 { |
|
94 <a name="l00094"></a>00094 iConsole->Printf(KExit); |
|
95 <a name="l00095"></a>00095 iConsole->Getch(); |
|
96 <a name="l00096"></a>00096 <span class="keyword">delete</span> iConsole; |
|
97 <a name="l00097"></a>00097 } |
|
98 <a name="l00098"></a>00098 |
|
99 <a name="l00109"></a>00109 <span class="keywordtype">void</span> CXmlExample::OnStartDocumentL(<span class="keyword">const</span> RDocumentParameters& aDocParam, TInt aErrorCode) |
|
100 <a name="l00110"></a>00110 { |
|
101 <a name="l00111"></a>00111 User::LeaveIfError(aErrorCode); |
|
102 <a name="l00112"></a>00112 iConsole->Printf(KOnStartDoc); |
|
103 <a name="l00113"></a>00113 |
|
104 <a name="l00114"></a>00114 <span class="keyword">const</span> TDesC8& encoding8 = aDocParam.CharacterSetName().DesC(); |
|
105 <a name="l00115"></a>00115 HBufC* encoding16= <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(encoding8); |
|
106 <a name="l00116"></a>00116 |
|
107 <a name="l00117"></a>00117 iConsole->Printf(KVersion, encoding16); |
|
108 <a name="l00118"></a>00118 CleanupStack::PopAndDestroy(encoding16); |
|
109 <a name="l00119"></a>00119 |
|
110 <a name="l00120"></a>00120 } |
|
111 <a name="l00121"></a>00121 |
|
112 <a name="l00130"></a><a class="code" href="class_c_xml_example.html#acb03c2dd56ed7b5dd3a4767caf310338">00130</a> <span class="keywordtype">void</span> <a class="code" href="class_c_xml_example.html#acb03c2dd56ed7b5dd3a4767caf310338">CXmlExample::OnEndDocumentL</a>(TInt aErrorCode) |
|
113 <a name="l00131"></a>00131 { |
|
114 <a name="l00132"></a>00132 User::LeaveIfError(aErrorCode); |
|
115 <a name="l00133"></a>00133 iConsole->Printf(KOnEndDoc); |
|
116 <a name="l00134"></a>00134 User::After(700000); <span class="comment">// 0.7 seconds</span> |
|
117 <a name="l00135"></a>00135 } |
|
118 <a name="l00136"></a>00136 |
|
119 <a name="l00148"></a>00148 <span class="keywordtype">void</span> CXmlExample::OnStartElementL(<span class="keyword">const</span> RTagInfo& aElement, <span class="keyword">const</span> RAttributeArray& aAttributes, TInt aErrorCode) |
|
120 <a name="l00149"></a>00149 { |
|
121 <a name="l00150"></a>00150 User::LeaveIfError(aErrorCode); |
|
122 <a name="l00151"></a>00151 |
|
123 <a name="l00152"></a>00152 <span class="keyword">const</span> TDesC8& localName8 = aElement.LocalName().DesC(); |
|
124 <a name="l00153"></a>00153 |
|
125 <a name="l00154"></a>00154 HBufC* localName16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localName8); |
|
126 <a name="l00155"></a>00155 |
|
127 <a name="l00156"></a>00156 iConsole->Printf(KStartElement,localName16); |
|
128 <a name="l00157"></a>00157 |
|
129 <a name="l00158"></a>00158 CleanupStack::PopAndDestroy(); <span class="comment">// Delete localName16</span> |
|
130 <a name="l00159"></a>00159 |
|
131 <a name="l00160"></a>00160 TInt nAttributes = aAttributes.Count(); |
|
132 <a name="l00161"></a>00161 <span class="keywordflow">for</span>(TInt i=0; i<nAttributes; i++) |
|
133 <a name="l00162"></a>00162 { |
|
134 <a name="l00163"></a>00163 <span class="keyword">const</span> RAttribute& attribute = aAttributes[i]; |
|
135 <a name="l00164"></a>00164 <span class="keyword">const</span> RTagInfo& nameInfo = attribute.Attribute(); |
|
136 <a name="l00165"></a>00165 |
|
137 <a name="l00166"></a>00166 <span class="keyword">const</span> TDesC8& localName8 = nameInfo.LocalName().DesC(); |
|
138 <a name="l00167"></a>00167 <span class="keyword">const</span> TDesC8& value8 = attribute.Value().DesC(); |
|
139 <a name="l00168"></a>00168 |
|
140 <a name="l00169"></a>00169 HBufC* localName16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localName8); |
|
141 <a name="l00170"></a>00170 HBufC* value16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(value8); |
|
142 <a name="l00171"></a>00171 |
|
143 <a name="l00172"></a>00172 iConsole->Printf(KAttrib, localName16, value16); |
|
144 <a name="l00173"></a>00173 CleanupStack::PopAndDestroy(2,localName16); |
|
145 <a name="l00174"></a>00174 } |
|
146 <a name="l00175"></a>00175 User::After(700000); <span class="comment">// 0.7 sec</span> |
|
147 <a name="l00176"></a>00176 |
|
148 <a name="l00177"></a>00177 } |
|
149 <a name="l00178"></a>00178 |
|
150 <a name="l00189"></a>00189 <span class="keywordtype">void</span> CXmlExample::OnEndElementL(<span class="keyword">const</span> RTagInfo& aElement, TInt aErrorCode) |
|
151 <a name="l00190"></a>00190 { |
|
152 <a name="l00191"></a>00191 User::LeaveIfError(aErrorCode); |
|
153 <a name="l00192"></a>00192 |
|
154 <a name="l00193"></a>00193 <span class="keyword">const</span> TDesC8& localName8 = aElement.LocalName().DesC(); |
|
155 <a name="l00194"></a>00194 HBufC* endBuf16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localName8); |
|
156 <a name="l00195"></a>00195 |
|
157 <a name="l00196"></a>00196 iConsole->Printf(KEndElement,endBuf16); |
|
158 <a name="l00197"></a>00197 |
|
159 <a name="l00198"></a>00198 CleanupStack::PopAndDestroy(endBuf16); |
|
160 <a name="l00199"></a>00199 } |
|
161 <a name="l00200"></a>00200 |
|
162 <a name="l00205"></a><a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">00205</a> HBufC* <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">CXmlExample::Copy8To16LC</a>(<span class="keyword">const</span> TDesC8& aDes) |
|
163 <a name="l00206"></a>00206 { |
|
164 <a name="l00207"></a>00207 HBufC* buf16 = HBufC::NewLC(aDes.Length()); |
|
165 <a name="l00208"></a>00208 buf16->Des().Copy(aDes); |
|
166 <a name="l00209"></a>00209 <span class="keywordflow">return</span> buf16; |
|
167 <a name="l00210"></a>00210 } |
|
168 <a name="l00211"></a>00211 |
|
169 <a name="l00212"></a>00212 |
|
170 <a name="l00228"></a><a class="code" href="class_c_xml_example.html#a56eecc5c8dd07c3224f4b40901fe26a5">00228</a> <span class="keywordtype">void</span> <a class="code" href="class_c_xml_example.html#a56eecc5c8dd07c3224f4b40901fe26a5">CXmlExample::OnContentL</a>(<span class="keyword">const</span> TDesC8& aData8, TInt aErrorCode) |
|
171 <a name="l00229"></a>00229 { |
|
172 <a name="l00230"></a>00230 User::LeaveIfError(aErrorCode); |
|
173 <a name="l00231"></a>00231 iConsole->Printf(KOnContent); |
|
174 <a name="l00232"></a>00232 |
|
175 <a name="l00233"></a>00233 HBufC* data16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(aData8); |
|
176 <a name="l00234"></a>00234 |
|
177 <a name="l00235"></a>00235 iConsole->Printf(KContent,data16); |
|
178 <a name="l00236"></a>00236 |
|
179 <a name="l00237"></a>00237 CleanupStack::PopAndDestroy(data16); |
|
180 <a name="l00238"></a>00238 |
|
181 <a name="l00239"></a>00239 } |
|
182 <a name="l00240"></a>00240 |
|
183 <a name="l00252"></a><a class="code" href="class_c_xml_example.html#ae95465e04bbefde583285c9109ec1bd6">00252</a> <span class="keywordtype">void</span> <a class="code" href="class_c_xml_example.html#ae95465e04bbefde583285c9109ec1bd6">CXmlExample::OnProcessingInstructionL</a>(<span class="keyword">const</span> TDesC8& aTarget8, <span class="keyword">const</span> TDesC8& aData8, TInt aErrorCode) |
|
184 <a name="l00253"></a>00253 { |
|
185 <a name="l00254"></a>00254 User::LeaveIfError(aErrorCode); |
|
186 <a name="l00255"></a>00255 iConsole->Printf(KOnProcInstrn); |
|
187 <a name="l00256"></a>00256 |
|
188 <a name="l00257"></a>00257 |
|
189 <a name="l00258"></a>00258 HBufC* target16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(aTarget8); |
|
190 <a name="l00259"></a>00259 HBufC* data16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(aData8); |
|
191 <a name="l00260"></a>00260 |
|
192 <a name="l00261"></a>00261 iConsole->Printf(KProcInstrn,target16,data16); |
|
193 <a name="l00262"></a>00262 CleanupStack::PopAndDestroy(2,target16); |
|
194 <a name="l00263"></a>00263 User::After(700000); <span class="comment">// 0.7 sec</span> |
|
195 <a name="l00264"></a>00264 } |
|
196 <a name="l00265"></a>00265 |
|
197 <a name="l00272"></a><a class="code" href="class_c_xml_example.html#a23c27211b331f46bc296a65aa3541bcf">00272</a> <span class="keywordtype">void</span> <a class="code" href="class_c_xml_example.html#a23c27211b331f46bc296a65aa3541bcf">CXmlExample::OnError</a>(TInt aError) |
|
198 <a name="l00273"></a>00273 { |
|
199 <a name="l00274"></a>00274 iError = aError; |
|
200 <a name="l00275"></a>00275 iConsole->Printf(KOnError,aError); |
|
201 <a name="l00276"></a>00276 iConsole->Printf(KPressAKey); |
|
202 <a name="l00277"></a>00277 iConsole->Getch(); |
|
203 <a name="l00278"></a>00278 } |
|
204 <a name="l00279"></a>00279 |
|
205 <a name="l00283"></a><a class="code" href="class_c_xml_example.html#ae79e3ab9f68abb8f6f953a90e8d552ee">00283</a> TAny* <a class="code" href="class_c_xml_example.html#ae79e3ab9f68abb8f6f953a90e8d552ee">CXmlExample::GetExtendedInterface</a>(<span class="keyword">const</span> TInt32 <span class="comment">/*aUid*/</span>) |
|
206 <a name="l00284"></a>00284 { |
|
207 <a name="l00285"></a>00285 <span class="comment">// do nothing.</span> |
|
208 <a name="l00286"></a>00286 <span class="keywordflow">return</span> NULL; |
|
209 <a name="l00287"></a>00287 } |
|
210 <a name="l00288"></a>00288 |
|
211 <a name="l00300"></a><a class="code" href="class_c_xml_example.html#a47b6d6f836f9f624e79304830bdcda4c">00300</a> <span class="keywordtype">void</span> <a class="code" href="class_c_xml_example.html#a47b6d6f836f9f624e79304830bdcda4c">CXmlExample::OnStartPrefixMappingL</a>(<span class="keyword">const</span> RString& aPrefix, <span class="keyword">const</span> RString& aUri, TInt aErrorCode) |
|
212 <a name="l00301"></a>00301 { |
|
213 <a name="l00302"></a>00302 User::LeaveIfError(aErrorCode); |
|
214 <a name="l00303"></a>00303 <span class="keyword">const</span> TDesC8& localPrefix8 = aPrefix.DesC(); |
|
215 <a name="l00304"></a>00304 HBufC* temp1 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localPrefix8); |
|
216 <a name="l00305"></a>00305 <span class="keyword">const</span> TDesC8& localUri8 = aUri.DesC(); |
|
217 <a name="l00306"></a>00306 HBufC* temp2 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localUri8); |
|
218 <a name="l00307"></a>00307 |
|
219 <a name="l00308"></a>00308 iConsole->Printf(KPrefixMap, temp1, temp2); |
|
220 <a name="l00309"></a>00309 CleanupStack::PopAndDestroy(2, temp1); |
|
221 <a name="l00310"></a>00310 |
|
222 <a name="l00311"></a>00311 iConsole->Printf(KPressAKey); |
|
223 <a name="l00312"></a>00312 iConsole->Getch(); |
|
224 <a name="l00313"></a>00313 |
|
225 <a name="l00314"></a>00314 } |
|
226 <a name="l00315"></a>00315 |
|
227 <a name="l00319"></a><a class="code" href="class_c_xml_example.html#ad7990a11e5d278a2107808c64e6374d4">00319</a> <span class="keywordtype">void</span> <a class="code" href="class_c_xml_example.html#ad7990a11e5d278a2107808c64e6374d4">CXmlExample::OnEndPrefixMappingL</a>(<span class="keyword">const</span> RString& aPrefix, TInt aErrorCode) |
|
228 <a name="l00320"></a>00320 { |
|
229 <a name="l00321"></a>00321 User::LeaveIfError(aErrorCode); |
|
230 <a name="l00322"></a>00322 <span class="keyword">const</span> TDesC8& localPrefix8 = aPrefix.DesC(); |
|
231 <a name="l00323"></a>00323 HBufC* temp = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localPrefix8); |
|
232 <a name="l00324"></a>00324 iConsole->Printf(KPrefixEnd, temp); |
|
233 <a name="l00325"></a>00325 CleanupStack::PopAndDestroy(temp); |
|
234 <a name="l00326"></a>00326 } |
|
235 <a name="l00327"></a>00327 |
|
236 <a name="l00331"></a><a class="code" href="class_c_xml_example.html#a576bd451612113613f1d27a7969940f1">00331</a> <span class="keywordtype">void</span> <a class="code" href="class_c_xml_example.html#a576bd451612113613f1d27a7969940f1">CXmlExample::OnIgnorableWhiteSpaceL</a>(<span class="keyword">const</span> TDesC8&, TInt) |
|
237 <a name="l00332"></a>00332 { |
|
238 <a name="l00333"></a>00333 |
|
239 <a name="l00334"></a>00334 } |
|
240 <a name="l00335"></a>00335 |
|
241 <a name="l00347"></a><a class="code" href="class_c_xml_example.html#a2eb7370a3adbe8ea81037b731029bba4">00347</a> <span class="keywordtype">void</span> <a class="code" href="class_c_xml_example.html#a2eb7370a3adbe8ea81037b731029bba4">CXmlExample::OnSkippedEntityL</a>(<span class="keyword">const</span> RString& aName, TInt aErrorCode) |
|
242 <a name="l00348"></a>00348 { |
|
243 <a name="l00349"></a>00349 User::LeaveIfError(aErrorCode); |
|
244 <a name="l00350"></a>00350 |
|
245 <a name="l00351"></a>00351 <span class="keyword">const</span> TDesC8& localName8 = aName.DesC(); |
|
246 <a name="l00352"></a>00352 HBufC* temp = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localName8); |
|
247 <a name="l00353"></a>00353 |
|
248 <a name="l00354"></a>00354 iConsole->Printf(KOnSkipped, temp); |
|
249 <a name="l00355"></a>00355 CleanupStack::PopAndDestroy(temp); |
|
250 <a name="l00356"></a>00356 User::After(700000); <span class="comment">// 0.7 sec delay </span> |
|
251 <a name="l00357"></a>00357 } |
|
252 <a name="l00358"></a>00358 |
|
253 <a name="l00362"></a><a class="code" href="class_c_xml_example.html#a3b6c99c50e79b71fbd83341a19fe2d73">00362</a> <span class="keywordtype">void</span> <a class="code" href="class_c_xml_example.html#a3b6c99c50e79b71fbd83341a19fe2d73">CXmlExample::ParseExampleDocumentsL</a>() |
|
254 <a name="l00363"></a>00363 { |
|
255 <a name="l00364"></a>00364 RFs fs; |
|
256 <a name="l00365"></a>00365 User::LeaveIfError(fs.Connect()); |
|
257 <a name="l00366"></a>00366 CleanupClosePushL(fs); |
|
258 <a name="l00367"></a>00367 |
|
259 <a name="l00368"></a>00368 RFile handle; |
|
260 <a name="l00369"></a>00369 TInt err; |
|
261 <a name="l00370"></a>00370 <span class="comment">// Open an example XML file for parsing</span> |
|
262 <a name="l00371"></a>00371 TRAP(err,handle.Open(fs, KSimpleXmlFile, EFileShareReadersOnly)); |
|
263 <a name="l00372"></a>00372 <span class="keywordflow">if</span> (err != KErrNone) |
|
264 <a name="l00373"></a>00373 { |
|
265 <a name="l00374"></a>00374 iConsole->Printf(KError); |
|
266 <a name="l00375"></a>00375 User::Leave(err); |
|
267 <a name="l00376"></a>00376 } |
|
268 <a name="l00377"></a>00377 CleanupClosePushL(handle); |
|
269 <a name="l00378"></a>00378 |
|
270 <a name="l00379"></a>00379 <span class="comment">// Open parser session for text/xml mime type</span> |
|
271 <a name="l00380"></a>00380 CParser* parser = CParser::NewLC(KXmlMimeType, *<span class="keyword">this</span>); |
|
272 <a name="l00381"></a>00381 |
|
273 <a name="l00382"></a>00382 iConsole->Printf(KParsingXml); |
|
274 <a name="l00383"></a>00383 iConsole->Printf(KPressAKey); |
|
275 <a name="l00384"></a>00384 iConsole->Getch(); |
|
276 <a name="l00385"></a>00385 |
|
277 <a name="l00386"></a>00386 err = parser->EnableFeature(EReportNamespaceMapping); |
|
278 <a name="l00387"></a>00387 |
|
279 <a name="l00388"></a>00388 <span class="keywordflow">if</span>(err==KErrNone) |
|
280 <a name="l00389"></a>00389 { |
|
281 <a name="l00390"></a>00390 iConsole->Printf(KNameSpaceRep); |
|
282 <a name="l00391"></a>00391 } |
|
283 <a name="l00392"></a>00392 |
|
284 <a name="l00393"></a>00393 <span class="comment">// Starts parser session</span> |
|
285 <a name="l00394"></a>00394 ParseL(*parser, handle); <span class="comment">// this will result in callbacks to handler</span> |
|
286 <a name="l00395"></a>00395 |
|
287 <a name="l00396"></a>00396 <span class="comment">// Closes the parser session.</span> |
|
288 <a name="l00397"></a>00397 CleanupStack::PopAndDestroy(parser); |
|
289 <a name="l00398"></a>00398 CleanupStack::Pop(&handle); |
|
290 <a name="l00399"></a>00399 |
|
291 <a name="l00400"></a>00400 <span class="comment">// Open an example WBXML file for parsing</span> |
|
292 <a name="l00401"></a>00401 TRAP(err,handle.Open(fs, KSimpleWbXmlFile, EFileShareReadersOnly)); |
|
293 <a name="l00402"></a>00402 <span class="keywordflow">if</span> (err != KErrNone) |
|
294 <a name="l00403"></a>00403 { |
|
295 <a name="l00404"></a>00404 iConsole->Printf(KError); |
|
296 <a name="l00405"></a>00405 User::Leave(err); |
|
297 <a name="l00406"></a>00406 } |
|
298 <a name="l00407"></a>00407 CleanupClosePushL(handle); |
|
299 <a name="l00408"></a>00408 |
|
300 <a name="l00409"></a>00409 parser = CParser::NewLC(KWbxmlMimeType, *<span class="keyword">this</span>); |
|
301 <a name="l00410"></a>00410 |
|
302 <a name="l00411"></a>00411 iConsole->Printf(KParsingWbXml); |
|
303 <a name="l00412"></a>00412 iConsole->Printf(KPressAKey); |
|
304 <a name="l00413"></a>00413 iConsole->Getch(); |
|
305 <a name="l00414"></a>00414 |
|
306 <a name="l00415"></a>00415 <span class="comment">// Starts parser session and active scheduler.</span> |
|
307 <a name="l00416"></a>00416 ParseL(*parser, handle); <span class="comment">// this will result in callbacks to handler</span> |
|
308 <a name="l00417"></a>00417 |
|
309 <a name="l00418"></a>00418 CleanupStack::PopAndDestroy(parser); |
|
310 <a name="l00419"></a>00419 CleanupStack::Pop(&handle); |
|
311 <a name="l00420"></a>00420 |
|
312 <a name="l00421"></a>00421 <span class="comment">// Open an example XML file for parsing using a parser specified with </span> |
|
313 <a name="l00422"></a>00422 <span class="comment">// MatchData. In this case, the default Symbian platform parser is requested.</span> |
|
314 <a name="l00423"></a>00423 |
|
315 <a name="l00424"></a>00424 TRAP(err,handle.Open(fs, KSimpleXmlFile, EFileShareReadersOnly)); |
|
316 <a name="l00425"></a>00425 <span class="keywordflow">if</span> (err != KErrNone) |
|
317 <a name="l00426"></a>00426 { |
|
318 <a name="l00427"></a>00427 iConsole->Printf(KError); |
|
319 <a name="l00428"></a>00428 User::Leave(err); |
|
320 <a name="l00429"></a>00429 } |
|
321 <a name="l00430"></a>00430 CleanupClosePushL(handle); |
|
322 <a name="l00431"></a>00431 |
|
323 <a name="l00432"></a>00432 CMatchData *matchData = CMatchData::NewLC(); |
|
324 <a name="l00433"></a>00433 matchData->SetMimeTypeL(KXmlMimeType); |
|
325 <a name="l00434"></a>00434 matchData->SetVariantL(_L8(<span class="stringliteral">"Symbian"</span>)); |
|
326 <a name="l00435"></a>00435 |
|
327 <a name="l00436"></a>00436 iConsole->Printf(KParsingMatch); |
|
328 <a name="l00437"></a>00437 iConsole->Printf(KPressAKey); |
|
329 <a name="l00438"></a>00438 iConsole->Getch(); |
|
330 <a name="l00439"></a>00439 |
|
331 <a name="l00440"></a>00440 parser = CParser::NewLC(*matchData, *<span class="keyword">this</span>); |
|
332 <a name="l00441"></a>00441 ParseL(*parser, handle); |
|
333 <a name="l00442"></a>00442 |
|
334 <a name="l00443"></a>00443 CleanupStack::PopAndDestroy(2,matchData); |
|
335 <a name="l00444"></a>00444 CleanupStack::PopAndDestroy(&handle); |
|
336 <a name="l00445"></a>00445 CleanupStack::PopAndDestroy(&fs); |
|
337 <a name="l00446"></a>00446 |
|
338 <a name="l00447"></a>00447 } |
|
339 <a name="l00448"></a>00448 |
|
340 <a name="l00449"></a><a class="code" href="xmlexample_8cpp.html#a689e0bf9aa924a1d7dc108665d44736c">00449</a> LOCAL_C <span class="keywordtype">void</span> MainL() |
|
341 <a name="l00450"></a>00450 { |
|
342 <a name="l00451"></a>00451 <a class="code" href="class_c_xml_example.html">CXmlExample</a>* app = <a class="code" href="class_c_xml_example.html#a9c72dee1761244c6964c76473995eba6">CXmlExample::NewL</a>(); |
|
343 <a name="l00452"></a>00452 CleanupStack::PushL(app); |
|
344 <a name="l00453"></a>00453 |
|
345 <a name="l00454"></a>00454 app-><a class="code" href="class_c_xml_example.html#a3b6c99c50e79b71fbd83341a19fe2d73">ParseExampleDocumentsL</a>(); |
|
346 <a name="l00455"></a>00455 CleanupStack::PopAndDestroy(app); |
|
347 <a name="l00456"></a>00456 |
|
348 <a name="l00457"></a>00457 } |
|
349 <a name="l00458"></a>00458 |
|
350 <a name="l00459"></a><a class="code" href="xmlexample_8cpp.html#a0f358e9c4355138f629b8c4f37310295">00459</a> GLDEF_C TInt E32Main() |
|
351 <a name="l00460"></a>00460 { |
|
352 <a name="l00461"></a>00461 __UHEAP_MARK; |
|
353 <a name="l00462"></a>00462 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
354 <a name="l00463"></a>00463 <span class="keywordflow">if</span>(cleanup == NULL) |
|
355 <a name="l00464"></a>00464 { |
|
356 <a name="l00465"></a>00465 <span class="keywordflow">return</span> KErrNoMemory; |
|
357 <a name="l00466"></a>00466 } |
|
358 <a name="l00467"></a>00467 TRAPD(err, MainL()); |
|
359 <a name="l00468"></a>00468 <span class="keywordflow">if</span>(err != KErrNone) |
|
360 <a name="l00469"></a>00469 { |
|
361 <a name="l00470"></a>00470 User::Panic(_L(<span class="stringliteral">"Failed to complete"</span>),err); |
|
362 <a name="l00471"></a>00471 } |
|
363 <a name="l00472"></a>00472 |
|
364 <a name="l00473"></a>00473 <span class="keyword">delete</span> cleanup; |
|
365 <a name="l00474"></a>00474 __UHEAP_MARKEND; |
|
366 <a name="l00475"></a>00475 <span class="keywordflow">return</span> KErrNone; |
|
367 <a name="l00476"></a>00476 } |
|
368 <a name="l00477"></a>00477 |
|
369 <a name="l00478"></a>00478 |
|
370 <a name="l00479"></a>00479 |
|
371 </pre></div></div> |
|
372 <hr size="1"/><address style="text-align: right;"><small>Generated by |
|
373 <a href="http://www.doxygen.org/index.html"> |
|
374 <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address> |
|
375 </body> |
|
376 </html> |