Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:How to generate XML using CSenDomFragment and CSenElement

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Reviewer Approved    Thumbs up icon sm.jpg
Article Metadata
Code ExampleTested with
Devices(s): N80
Compatibility
Platform(s): S60 3rd Edition
S60 3rd Edition (initial release)
Article
Keywords: CSenDomFragment and CSenElement
Created: savaj (09 May 2009)
Last edited: vineet.jain (02 Nov 2012)



Contents

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

This page was last modified on 2 November 2012, at 08:46.
17 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×