Create xml in symbian

Source: Internet
Author: User
Symbian (Generate XML CSenDomFragment) to Generate XML

XML parsing is a problem for our project managers.
Now, XML parsing is inevitable.
Today, let's take a look at how XML is generated.

In fact, there is a simple way to generate XML by ourselves.
Of course, the system also provides us with APIs for us to generate XML.
Let's take a look at how to handle it.
Continue to the SYMBIAN path, and leave footprints to be forgotten. Ga !!!

// System method for generating XML

CSenDomFragment * pSenDomFragment = CSenDomFragment: NewL (_ L8 ("Mark15021 "));

// Generate a node
CSenElement * Root = pSenDomFragment-> AsElement (). CreateElementL (_ L8 (""), _ L8 ("Root "));
// Set its attribute
Root-> AddAttrL (_ L8 ("width"), _ L8 ("50 "));
Root-> AddAttrL (_ L8 ("height"), _ L8 ("50 "));

// Generate the node
CSenElement * Child1 = pSenDomFragment-> AsElement (). CreateElementL (_ L8 (""), _ L8

("Mark1 "));
Child1-> AddAttrL (_ L8 ("name"), _ L8 ("Mark15021 "));
Child1-> AddAttrL (_ L8 ("surname"), _ L8 ("Mark15021 "));
Child1-> AddAttrL (_ L8 ("author"), _ L8 ("Mark15021 "));


// Generate the node
CSenElement * Child2 = pSenDomFragment-> AsElement (). CreateElementL (_ L8 (""), _ L8

("Mark2 "));
Child2-> AddAttrL (_ L8 ("name"), _ L8 ("Mark15021 "));
Child2-> AddAttrL (_ L8 ("surname"), _ L8 ("Mark15021 "));
Child2-> AddAttrL (_ L8 ("author"), _ L8 ("Mark15021 "));

// Create child tag
CSenElement * Child3 = pSenDomFragment-> AsElement (). CreateElementL (_ L8 (""), _ L8

("Date "));
TPtrC8 SetxmlParam1Content = Child3-> SetContentL (_ L8 ("Monday, January 01,201 0 "));

// Setting parent node and transfering ownership.
// Relationship between specified nodes
CSenElement & Child11 = Root-> AddElementL (* Child1 );
CSenElement & Child21 = Root-> AddElementL (* Child2 );
CSenElement & Child31 = Root-> AddElementL (* Child3 );

RFile file;

// Generate an XML file
If (KErrNone! = File. Open (aFs, _ L ("c: \ data \ MarkXML"), EFileWrite ))

File. Replace (aFs, _ L ("c: \ data \ MarkXML"), EFileWrite );

// Set the XML encoding format
// Generate XML in unicode and ascall formats
HBufC8 * xml = Root-> AsXmlL ();

If (xml)
File. Write (xml-> Des ());
File. Close ();

Delete xml;
Delete pSenDomFragment;
Delete Root;

// XML soil generation method

TBuf8 <128> startBuf;
StartBuf. Append (_ L8 ("<? Xml version = \ "1.0 \" encoding = \ "UTF-8 \"?> "));
StartBuf. Append (_ L8 ("\ r \ n <xml> "));
// Xml trail
TBuf8 <32> endBuf;
EndBuf. Append (_ L8 ("\ r \ n </xml> "));

_ LIT8 (KTypeFormat, "<Type> % d </Type> ");
_ LIT8 (KTrueNameFormat, "<Name> % S </Name> ");

BufType. AppendFormat (KTypeFormat, iType );
/// Get name
BufTrueName. AppendFormat (KTrueNameFormat, & bufName );

// Generate the XML header
Err = file. Write (startBuf );
Err = file. Write (_ L8 ("\ r \ n "));
// Generate XML data
Err = file. Write (bufType );
Err = file. Write (_ L8 ("\ r \ n "));
Err = file. Write (bufName );
// Generate the end of the XML file
Err = file. Write (endBuf );

The above code passes the test on N95

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.