You Are Here:

Community: Wiki

This page was last modified on 29 September 2009, at 06:18.

How to generate XML using CSenDomFragment and CSenElement

From Forum Nokia Wiki

Reviewer Approved   



ID - Creation date 9 May 2009
Platform S60 3rd Edition Tested on devices N80
Category Symbian C++ Subcategory


Keywords (APIs, classes, methods, functions): CSenDomFragment and CSenElement


Overview

This following example shows how to generate an xml using CSenDomFragment and CSenElement in S60 3rd edition. it generates MyXML and save it to C:\data directory.

The sample example creates a new root element, add attribute to it, generates child node with attribute and data.

Headers Required

#include <senelement.h> 
#include <sendomfragment.h>

Library Needed

LIBRARY   SenXml.lib

Capability Required

Capability  None
void CGenerateXMLAppUi::GenerateXML()
{
CSenDomFragment* pSenDomFragment = CSenDomFragment::NewL(_L8("LocalName"));
 
// create root Tag
CSenElement* Root = pSenDomFragment->AsElement().CreateElementL(_L8(""),_L8("Root"));
//set its attribute
Root->AddAttrL(_L8("volume"),_L8("0"));
Root->AddAttrL(_L8("video"),_L8("1"));
 
 
// create child tag
CSenElement* Child1 = pSenDomFragment->AsElement().CreateElementL(_L8(""),_L8("Item"));
Child1->AddAttrL(_L8("name"),_L8("kamlesh"));
Child1->AddAttrL(_L8("surname"),_L8("sangani"));
Child1->AddAttrL(_L8("author"),_L8("bapu"));
 
 
// create child tag
CSenElement* Child2 = pSenDomFragment->AsElement().CreateElementL(_L8(""),_L8("Item"));
Child2->AddAttrL(_L8("name"),_L8("abc"));
Child2->AddAttrL(_L8("surname"),_L8("def"));
Child2->AddAttrL(_L8("author"),_L8("someone"));
 
// create child tag
CSenElement* Child3 = pSenDomFragment->AsElement().CreateElementL(_L8(""),_L8("Date"));
TPtrC8 SetxmlParam1Content = Child3->SetContentL(_L8("Friday, May 09, 2009"));
 
//setting parent node and transfering ownership.
CSenElement& Child11 = Root->AddElementL(*Child1);
CSenElement& Child21 = Root->AddElementL(*Child2);
CSenElement& Child31 = Root->AddElementL(*Child3);
 
RFile file;
 
if (KErrNone != file.Open(CCoeEnv::Static()->FsSession(), _L("c:\\data\\MyXML"), EFileWrite))
file.Replace(CCoeEnv::Static()->FsSession(), _L("c:\\data\\MyXML"), EFileWrite);
 
HBufC8* xml = Root->AsXmlL();
 
 
if(xml)
file.Write(xml->Des());
file.Close();
 
delete xml;
delete pSenDomFragment;
delete Root;
 
}

Postconditions

The code snippet is expected to generate XML file as shown below.

<Root volume="0" video="1">
<Item name="kamlesh" surname="sangani" author="bapu"/>
<Item name="abc" surname="def" author="someone"/>
<Date>Friday, May 01, 2009</Date>
</Root>

Download Code Example

Related Link

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia