Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/xmlexample_8cpp_source.html
author Dominic Pinkman <dominic.pinkman@nokia.com>
Fri, 13 Aug 2010 16:47:46 +0100
changeset 14 578be2adaf3e
parent 6 43e37759235e
permissions -rw-r--r--
Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>TB9.2 Example Applications: examples/SysLibs/XmlExample/xmlexample.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2 -->
<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>
<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span>
<a name="l00004"></a>00004 <span class="comment">// under the terms of &quot;Eclipse Public License v1.0&quot;</span>
<a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span>
<a name="l00006"></a>00006 <span class="comment">// at the URL &quot;http://www.eclipse.org/legal/epl-v10.html&quot;.</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span>
<a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// Contributors:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// Description:</span>
<a name="l00014"></a>00014 <span class="comment">// This example program demonstrates the use of XML Framework APIs. </span>
<a name="l00015"></a>00015 <span class="comment">// The code implements all the functions of MContentHandler class.</span>
<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>
<a name="l00017"></a>00017 <span class="comment">// write an XML file you can refer to this URL http://www.w3schools.com/xml/.</span>
<a name="l00018"></a>00018 <span class="comment">//</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 
<a name="l00025"></a>00025 <span class="preprocessor">#include &quot;xmlexample.h&quot;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;xml/documentparameters.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;xml/parserfeature.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;xml/matchdata.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;e32cons.h&gt;</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="keyword">using namespace </span>Xml;
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTitle, <span class="stringliteral">&quot;XML example&quot;</span>);
<a name="l00034"></a>00034 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KStartKey, <span class="stringliteral">&quot;\nThe example parses the given XML and WBXML files. Press any key to start\n&quot;</span>);
<a name="l00035"></a>00035 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPressAKey,<span class="stringliteral">&quot;\nPress any key to continue \n&quot;</span>);
<a name="l00036"></a>00036 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KExit,<span class="stringliteral">&quot;\n Press any key to exit the application \n&quot;</span>);
<a name="l00037"></a>00037 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KParsingXml,<span class="stringliteral">&quot;\nParsing the XML file&quot;</span>);
<a name="l00038"></a>00038 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KParsingWbXml,<span class="stringliteral">&quot;\nParsing the WBXML file&quot;</span>);
<a name="l00039"></a>00039 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KParsingMatch,<span class="stringliteral">&quot;\nParsing the XML file using match data criteria&quot;</span>);
<a name="l00040"></a>00040 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KError,<span class="stringliteral">&quot;\n Could not open the XML file. Please check if the file exists.&quot;</span>);
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnStartDoc,<span class="stringliteral">&quot;\n&lt;!-- CXmlExample::OnStartDocumentL --&gt;\n&quot;</span>);
<a name="l00043"></a>00043 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnEndDoc,<span class="stringliteral">&quot;\n&lt;!-- CXmlExample::OnEndDocumentL --&gt;\n&quot;</span>);
<a name="l00044"></a>00044 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnContent,<span class="stringliteral">&quot;&lt;!-- CXmlExample::OnContentL --&gt;&quot;</span>);
<a name="l00045"></a>00045 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnProcInstrn,<span class="stringliteral">&quot;\n&lt;!-- CXmlExample::OnProcessingInstructionL --&gt;\n&quot;</span>);
<a name="l00046"></a>00046 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnError,<span class="stringliteral">&quot;CXmlExample::OnError - ERROR: code=%d\n&quot;</span>);
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KVersion,<span class="stringliteral">&quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;%S\&quot;?&gt;\n&quot;</span>);
<a name="l00049"></a>00049 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KStartElement,<span class="stringliteral">&quot;\nStart of element: &lt;%S&gt;\n&quot;</span>);
<a name="l00050"></a>00050 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KEndElement,<span class="stringliteral">&quot;\nEnd of element: &lt;/%S&gt;\n&quot;</span>);
<a name="l00051"></a>00051 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KContent,<span class="stringliteral">&quot;%S\n&quot;</span>);
<a name="l00052"></a>00052 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KAttrib,<span class="stringliteral">&quot;The attribute of element &lt;%S&gt;=\&quot;%S\&quot;&quot;</span>);
<a name="l00053"></a>00053 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KProcInstrn,<span class="stringliteral">&quot;&lt;?%S %S?&gt;\n&quot;</span>);
<a name="l00054"></a>00054 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KOnSkipped, <span class="stringliteral">&quot;Found skipped entity %S&quot;</span>);
<a name="l00055"></a>00055 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KNameSpaceRep,<span class="stringliteral">&quot;\nNamespace mapping reporting enabled\n &quot;</span>);
<a name="l00056"></a>00056 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPrefixMap, <span class="stringliteral">&quot;\nThe prefix is %S and URI is %S\n&quot;</span>);
<a name="l00057"></a>00057 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPrefixEnd, <span class="stringliteral">&quot;End of prefix URI mapping %S\n&quot;</span>);
<a name="l00058"></a>00058 
<a name="l00059"></a>00059 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KSimpleXmlFile,    <span class="stringliteral">&quot;z:\\private\\E80000AE\\xmlexample.xml&quot;</span>);
<a name="l00060"></a>00060 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KSimpleWbXmlFile,    <span class="stringliteral">&quot;z:\\private\\E80000AE\\xmlexample.wbxml&quot;</span>);
<a name="l00061"></a>00061 _LIT8(KXmlMimeType, <span class="stringliteral">&quot;text/xml&quot;</span>);
<a name="l00062"></a>00062 _LIT8(KWbxmlMimeType, <span class="stringliteral">&quot;text/wbxml&quot;</span>);
<a name="l00063"></a>00063 
<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>()
<a name="l00069"></a>00069         {
<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>();
<a name="l00071"></a>00071         CleanupStack::PushL(<span class="keyword">self</span>);
<a name="l00072"></a>00072         <span class="keyword">self</span>-&gt;ConstructL();
<a name="l00073"></a>00073         CleanupStack::Pop();
<a name="l00074"></a>00074         <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00075"></a>00075         }
<a name="l00076"></a>00076 
<a name="l00077"></a>00077 CXmlExample::CXmlExample()
<a name="l00078"></a>00078         :iError(KErrNone)
<a name="l00079"></a>00079         {
<a name="l00080"></a>00080         }
<a name="l00081"></a>00081 
<a name="l00082"></a>00082 <span class="keywordtype">void</span> CXmlExample::ConstructL()
<a name="l00083"></a>00083         {
<a name="l00084"></a>00084         iConsole = <a class="code" href="class_c_xml_example.html#a9c72dee1761244c6964c76473995eba6">Console::NewL</a>(KTitle,TSize(KConsFullScreen,KConsFullScreen));
<a name="l00085"></a>00085         iConsole-&gt;Printf ( KStartKey);
<a name="l00086"></a>00086         iConsole-&gt;Getch ();
<a name="l00087"></a>00087         }
<a name="l00088"></a>00088 
<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>()
<a name="l00093"></a>00093         {
<a name="l00094"></a>00094         iConsole-&gt;Printf(KExit);
<a name="l00095"></a>00095         iConsole-&gt;Getch();
<a name="l00096"></a>00096         <span class="keyword">delete</span> iConsole;
<a name="l00097"></a>00097         }
<a name="l00098"></a>00098 
<a name="l00109"></a>00109 <span class="keywordtype">void</span> CXmlExample::OnStartDocumentL(<span class="keyword">const</span> RDocumentParameters&amp; aDocParam, TInt aErrorCode)
<a name="l00110"></a>00110         {
<a name="l00111"></a>00111         User::LeaveIfError(aErrorCode);
<a name="l00112"></a>00112         iConsole-&gt;Printf(KOnStartDoc);
<a name="l00113"></a>00113 
<a name="l00114"></a>00114         <span class="keyword">const</span> TDesC8&amp; encoding8 = aDocParam.CharacterSetName().DesC();
<a name="l00115"></a>00115         HBufC* encoding16= <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(encoding8);
<a name="l00116"></a>00116 
<a name="l00117"></a>00117         iConsole-&gt;Printf(KVersion, encoding16);
<a name="l00118"></a>00118         CleanupStack::PopAndDestroy(encoding16);
<a name="l00119"></a>00119 
<a name="l00120"></a>00120         }
<a name="l00121"></a>00121         
<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)
<a name="l00131"></a>00131         {
<a name="l00132"></a>00132         User::LeaveIfError(aErrorCode);
<a name="l00133"></a>00133         iConsole-&gt;Printf(KOnEndDoc);
<a name="l00134"></a>00134         User::After(700000); <span class="comment">// 0.7 seconds</span>
<a name="l00135"></a>00135         }
<a name="l00136"></a>00136 
<a name="l00148"></a>00148 <span class="keywordtype">void</span> CXmlExample::OnStartElementL(<span class="keyword">const</span> RTagInfo&amp; aElement, <span class="keyword">const</span> RAttributeArray&amp; aAttributes, TInt aErrorCode)
<a name="l00149"></a>00149         {
<a name="l00150"></a>00150         User::LeaveIfError(aErrorCode);
<a name="l00151"></a>00151 
<a name="l00152"></a>00152         <span class="keyword">const</span> TDesC8&amp; localName8 = aElement.LocalName().DesC();
<a name="l00153"></a>00153         
<a name="l00154"></a>00154         HBufC* localName16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localName8);
<a name="l00155"></a>00155         
<a name="l00156"></a>00156         iConsole-&gt;Printf(KStartElement,localName16);
<a name="l00157"></a>00157 
<a name="l00158"></a>00158         CleanupStack::PopAndDestroy();  <span class="comment">// Delete localName16</span>
<a name="l00159"></a>00159 
<a name="l00160"></a>00160         TInt nAttributes = aAttributes.Count();
<a name="l00161"></a>00161         <span class="keywordflow">for</span>(TInt i=0; i&lt;nAttributes; i++)
<a name="l00162"></a>00162                 {
<a name="l00163"></a>00163                 <span class="keyword">const</span> RAttribute&amp; attribute = aAttributes[i];
<a name="l00164"></a>00164                 <span class="keyword">const</span> RTagInfo&amp; nameInfo = attribute.Attribute();
<a name="l00165"></a>00165 
<a name="l00166"></a>00166                 <span class="keyword">const</span> TDesC8&amp; localName8 = nameInfo.LocalName().DesC();
<a name="l00167"></a>00167                 <span class="keyword">const</span> TDesC8&amp; value8 = attribute.Value().DesC();
<a name="l00168"></a>00168 
<a name="l00169"></a>00169                 HBufC* localName16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localName8);
<a name="l00170"></a>00170                 HBufC* value16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(value8);
<a name="l00171"></a>00171 
<a name="l00172"></a>00172                 iConsole-&gt;Printf(KAttrib, localName16, value16);
<a name="l00173"></a>00173                 CleanupStack::PopAndDestroy(2,localName16);
<a name="l00174"></a>00174                 }
<a name="l00175"></a>00175         User::After(700000); <span class="comment">// 0.7 sec</span>
<a name="l00176"></a>00176 
<a name="l00177"></a>00177         }
<a name="l00178"></a>00178 
<a name="l00189"></a>00189 <span class="keywordtype">void</span> CXmlExample::OnEndElementL(<span class="keyword">const</span> RTagInfo&amp; aElement, TInt aErrorCode)
<a name="l00190"></a>00190         {
<a name="l00191"></a>00191         User::LeaveIfError(aErrorCode);
<a name="l00192"></a>00192         
<a name="l00193"></a>00193         <span class="keyword">const</span> TDesC8&amp; localName8 = aElement.LocalName().DesC();
<a name="l00194"></a>00194         HBufC* endBuf16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localName8);
<a name="l00195"></a>00195         
<a name="l00196"></a>00196         iConsole-&gt;Printf(KEndElement,endBuf16);
<a name="l00197"></a>00197         
<a name="l00198"></a>00198          CleanupStack::PopAndDestroy(endBuf16);
<a name="l00199"></a>00199         }
<a name="l00200"></a>00200 
<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&amp; aDes)
<a name="l00206"></a>00206         {
<a name="l00207"></a>00207         HBufC* buf16 = HBufC::NewLC(aDes.Length());
<a name="l00208"></a>00208         buf16-&gt;Des().Copy(aDes);
<a name="l00209"></a>00209         <span class="keywordflow">return</span> buf16; 
<a name="l00210"></a>00210         }
<a name="l00211"></a>00211 
<a name="l00212"></a>00212 
<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&amp; aData8, TInt aErrorCode)
<a name="l00229"></a>00229         {
<a name="l00230"></a>00230         User::LeaveIfError(aErrorCode);
<a name="l00231"></a>00231         iConsole-&gt;Printf(KOnContent);
<a name="l00232"></a>00232         
<a name="l00233"></a>00233         HBufC* data16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(aData8);
<a name="l00234"></a>00234         
<a name="l00235"></a>00235         iConsole-&gt;Printf(KContent,data16);      
<a name="l00236"></a>00236         
<a name="l00237"></a>00237         CleanupStack::PopAndDestroy(data16);
<a name="l00238"></a>00238         
<a name="l00239"></a>00239         }
<a name="l00240"></a>00240 
<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&amp; aTarget8, <span class="keyword">const</span> TDesC8&amp; aData8, TInt aErrorCode)
<a name="l00253"></a>00253         {
<a name="l00254"></a>00254         User::LeaveIfError(aErrorCode);
<a name="l00255"></a>00255         iConsole-&gt;Printf(KOnProcInstrn);
<a name="l00256"></a>00256 
<a name="l00257"></a>00257 
<a name="l00258"></a>00258         HBufC* target16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(aTarget8);
<a name="l00259"></a>00259         HBufC* data16 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(aData8);
<a name="l00260"></a>00260 
<a name="l00261"></a>00261         iConsole-&gt;Printf(KProcInstrn,target16,data16);
<a name="l00262"></a>00262         CleanupStack::PopAndDestroy(2,target16);
<a name="l00263"></a>00263         User::After(700000); <span class="comment">// 0.7 sec</span>
<a name="l00264"></a>00264         }
<a name="l00265"></a>00265 
<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)
<a name="l00273"></a>00273         {
<a name="l00274"></a>00274         iError = aError;
<a name="l00275"></a>00275         iConsole-&gt;Printf(KOnError,aError);
<a name="l00276"></a>00276         iConsole-&gt;Printf(KPressAKey);
<a name="l00277"></a>00277         iConsole-&gt;Getch();
<a name="l00278"></a>00278         }
<a name="l00279"></a>00279 
<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>)
<a name="l00284"></a>00284         {
<a name="l00285"></a>00285         <span class="comment">// do nothing.</span>
<a name="l00286"></a>00286         <span class="keywordflow">return</span> NULL;
<a name="l00287"></a>00287         }
<a name="l00288"></a>00288         
<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&amp; aPrefix, <span class="keyword">const</span> RString&amp; aUri, TInt aErrorCode)
<a name="l00301"></a>00301         {
<a name="l00302"></a>00302         User::LeaveIfError(aErrorCode);
<a name="l00303"></a>00303         <span class="keyword">const</span> TDesC8&amp; localPrefix8 = aPrefix.DesC();
<a name="l00304"></a>00304         HBufC* temp1 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localPrefix8);
<a name="l00305"></a>00305         <span class="keyword">const</span> TDesC8&amp; localUri8 = aUri.DesC();
<a name="l00306"></a>00306         HBufC* temp2 = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localUri8);
<a name="l00307"></a>00307         
<a name="l00308"></a>00308         iConsole-&gt;Printf(KPrefixMap, temp1, temp2);
<a name="l00309"></a>00309         CleanupStack::PopAndDestroy(2, temp1);
<a name="l00310"></a>00310         
<a name="l00311"></a>00311         iConsole-&gt;Printf(KPressAKey);
<a name="l00312"></a>00312         iConsole-&gt;Getch();
<a name="l00313"></a>00313                 
<a name="l00314"></a>00314         }
<a name="l00315"></a>00315         
<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&amp; aPrefix, TInt aErrorCode)
<a name="l00320"></a>00320         {
<a name="l00321"></a>00321         User::LeaveIfError(aErrorCode);
<a name="l00322"></a>00322         <span class="keyword">const</span> TDesC8&amp; localPrefix8 = aPrefix.DesC();
<a name="l00323"></a>00323         HBufC* temp = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localPrefix8);
<a name="l00324"></a>00324         iConsole-&gt;Printf(KPrefixEnd, temp);
<a name="l00325"></a>00325         CleanupStack::PopAndDestroy(temp);
<a name="l00326"></a>00326         }
<a name="l00327"></a>00327 
<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&amp;, TInt)
<a name="l00332"></a>00332         {
<a name="l00333"></a>00333         
<a name="l00334"></a>00334         }
<a name="l00335"></a>00335 
<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&amp; aName, TInt aErrorCode)
<a name="l00348"></a>00348         {
<a name="l00349"></a>00349         User::LeaveIfError(aErrorCode);
<a name="l00350"></a>00350         
<a name="l00351"></a>00351         <span class="keyword">const</span> TDesC8&amp; localName8 = aName.DesC();
<a name="l00352"></a>00352         HBufC* temp = <a class="code" href="class_c_xml_example.html#a5a29447b6066d26a5eafcbd5164e4bc9">Copy8To16LC</a>(localName8);
<a name="l00353"></a>00353         
<a name="l00354"></a>00354         iConsole-&gt;Printf(KOnSkipped, temp);
<a name="l00355"></a>00355         CleanupStack::PopAndDestroy(temp);
<a name="l00356"></a>00356         User::After(700000); <span class="comment">// 0.7 sec delay           </span>
<a name="l00357"></a>00357         }
<a name="l00358"></a>00358 
<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>()
<a name="l00363"></a>00363         {
<a name="l00364"></a>00364         RFs fs;
<a name="l00365"></a>00365         User::LeaveIfError(fs.Connect());
<a name="l00366"></a>00366         CleanupClosePushL(fs);
<a name="l00367"></a>00367 
<a name="l00368"></a>00368         RFile handle;
<a name="l00369"></a>00369         TInt err;
<a name="l00370"></a>00370         <span class="comment">// Open an example XML file for parsing</span>
<a name="l00371"></a>00371         TRAP(err,handle.Open(fs, KSimpleXmlFile, EFileShareReadersOnly));
<a name="l00372"></a>00372         <span class="keywordflow">if</span> (err != KErrNone)
<a name="l00373"></a>00373                 {
<a name="l00374"></a>00374                 iConsole-&gt;Printf(KError);
<a name="l00375"></a>00375                 User::Leave(err);
<a name="l00376"></a>00376                 }
<a name="l00377"></a>00377         CleanupClosePushL(handle);
<a name="l00378"></a>00378 
<a name="l00379"></a>00379         <span class="comment">// Open parser session for text/xml mime type</span>
<a name="l00380"></a>00380         CParser* parser = CParser::NewLC(KXmlMimeType, *<span class="keyword">this</span>);
<a name="l00381"></a>00381         
<a name="l00382"></a>00382         iConsole-&gt;Printf(KParsingXml);
<a name="l00383"></a>00383         iConsole-&gt;Printf(KPressAKey);
<a name="l00384"></a>00384         iConsole-&gt;Getch();
<a name="l00385"></a>00385         
<a name="l00386"></a>00386         err = parser-&gt;EnableFeature(EReportNamespaceMapping);
<a name="l00387"></a>00387          
<a name="l00388"></a>00388         <span class="keywordflow">if</span>(err==KErrNone) 
<a name="l00389"></a>00389         {
<a name="l00390"></a>00390         iConsole-&gt;Printf(KNameSpaceRep);
<a name="l00391"></a>00391         } 
<a name="l00392"></a>00392 
<a name="l00393"></a>00393         <span class="comment">// Starts parser session</span>
<a name="l00394"></a>00394         ParseL(*parser, handle); <span class="comment">// this will result in callbacks to handler</span>
<a name="l00395"></a>00395         
<a name="l00396"></a>00396         <span class="comment">// Closes the parser session.</span>
<a name="l00397"></a>00397         CleanupStack::PopAndDestroy(parser);
<a name="l00398"></a>00398         CleanupStack::Pop(&amp;handle);
<a name="l00399"></a>00399 
<a name="l00400"></a>00400         <span class="comment">// Open an example WBXML file for parsing</span>
<a name="l00401"></a>00401         TRAP(err,handle.Open(fs, KSimpleWbXmlFile, EFileShareReadersOnly));
<a name="l00402"></a>00402         <span class="keywordflow">if</span> (err != KErrNone)
<a name="l00403"></a>00403                 {
<a name="l00404"></a>00404                 iConsole-&gt;Printf(KError);
<a name="l00405"></a>00405                 User::Leave(err);
<a name="l00406"></a>00406                 }
<a name="l00407"></a>00407         CleanupClosePushL(handle);
<a name="l00408"></a>00408 
<a name="l00409"></a>00409         parser = CParser::NewLC(KWbxmlMimeType, *<span class="keyword">this</span>);
<a name="l00410"></a>00410         
<a name="l00411"></a>00411         iConsole-&gt;Printf(KParsingWbXml);
<a name="l00412"></a>00412         iConsole-&gt;Printf(KPressAKey);
<a name="l00413"></a>00413         iConsole-&gt;Getch();
<a name="l00414"></a>00414         
<a name="l00415"></a>00415         <span class="comment">// Starts parser session and active scheduler.</span>
<a name="l00416"></a>00416         ParseL(*parser, handle); <span class="comment">// this will result in callbacks to handler</span>
<a name="l00417"></a>00417 
<a name="l00418"></a>00418         CleanupStack::PopAndDestroy(parser);
<a name="l00419"></a>00419         CleanupStack::Pop(&amp;handle);
<a name="l00420"></a>00420 
<a name="l00421"></a>00421         <span class="comment">// Open an example XML file for parsing using a parser specified with </span>
<a name="l00422"></a>00422         <span class="comment">// MatchData. In this case, the default Symbian platform parser is requested.</span>
<a name="l00423"></a>00423         
<a name="l00424"></a>00424         TRAP(err,handle.Open(fs, KSimpleXmlFile, EFileShareReadersOnly));
<a name="l00425"></a>00425         <span class="keywordflow">if</span> (err != KErrNone)
<a name="l00426"></a>00426                 {
<a name="l00427"></a>00427                 iConsole-&gt;Printf(KError);
<a name="l00428"></a>00428                 User::Leave(err);
<a name="l00429"></a>00429                 }       
<a name="l00430"></a>00430         CleanupClosePushL(handle);
<a name="l00431"></a>00431 
<a name="l00432"></a>00432         CMatchData *matchData = CMatchData::NewLC();
<a name="l00433"></a>00433         matchData-&gt;SetMimeTypeL(KXmlMimeType);
<a name="l00434"></a>00434         matchData-&gt;SetVariantL(_L8(<span class="stringliteral">&quot;Symbian&quot;</span>));
<a name="l00435"></a>00435         
<a name="l00436"></a>00436         iConsole-&gt;Printf(KParsingMatch);
<a name="l00437"></a>00437         iConsole-&gt;Printf(KPressAKey);
<a name="l00438"></a>00438         iConsole-&gt;Getch();
<a name="l00439"></a>00439         
<a name="l00440"></a>00440         parser = CParser::NewLC(*matchData, *<span class="keyword">this</span>);
<a name="l00441"></a>00441         ParseL(*parser, handle);
<a name="l00442"></a>00442         
<a name="l00443"></a>00443         CleanupStack::PopAndDestroy(2,matchData);
<a name="l00444"></a>00444         CleanupStack::PopAndDestroy(&amp;handle);
<a name="l00445"></a>00445         CleanupStack::PopAndDestroy(&amp;fs);
<a name="l00446"></a>00446         
<a name="l00447"></a>00447         }
<a name="l00448"></a>00448 
<a name="l00449"></a><a class="code" href="xmlexample_8cpp.html#a689e0bf9aa924a1d7dc108665d44736c">00449</a> LOCAL_C <span class="keywordtype">void</span> MainL()
<a name="l00450"></a>00450         {
<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>();
<a name="l00452"></a>00452         CleanupStack::PushL(app);
<a name="l00453"></a>00453         
<a name="l00454"></a>00454         app-&gt;<a class="code" href="class_c_xml_example.html#a3b6c99c50e79b71fbd83341a19fe2d73">ParseExampleDocumentsL</a>();
<a name="l00455"></a>00455         CleanupStack::PopAndDestroy(app);
<a name="l00456"></a>00456 
<a name="l00457"></a>00457         }
<a name="l00458"></a>00458 
<a name="l00459"></a><a class="code" href="xmlexample_8cpp.html#a0f358e9c4355138f629b8c4f37310295">00459</a> GLDEF_C TInt E32Main()
<a name="l00460"></a>00460         {
<a name="l00461"></a>00461     __UHEAP_MARK;
<a name="l00462"></a>00462     CTrapCleanup* cleanup = CTrapCleanup::New();
<a name="l00463"></a>00463     <span class="keywordflow">if</span>(cleanup == NULL)
<a name="l00464"></a>00464         {
<a name="l00465"></a>00465         <span class="keywordflow">return</span> KErrNoMemory;
<a name="l00466"></a>00466         }
<a name="l00467"></a>00467     TRAPD(err, MainL());
<a name="l00468"></a>00468         <span class="keywordflow">if</span>(err != KErrNone)
<a name="l00469"></a>00469                 {
<a name="l00470"></a>00470                 User::Panic(_L(<span class="stringliteral">&quot;Failed to complete&quot;</span>),err);
<a name="l00471"></a>00471                 }
<a name="l00472"></a>00472 
<a name="l00473"></a>00473     <span class="keyword">delete</span> cleanup;
<a name="l00474"></a>00474     __UHEAP_MARKEND;
<a name="l00475"></a>00475     <span class="keywordflow">return</span> KErrNone;
<a name="l00476"></a>00476         }
<a name="l00477"></a>00477 
<a name="l00478"></a>00478 
<a name="l00479"></a>00479 
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
</body>
</html>