Parse XML with IKS

Source: Internet
Author: User
Tags readfile

From Network Resources

 

Steps:

 

1 go to http://code.google.com/p/iksemel/download the latest iksemel1.4;

2. Add the header files under the include directory and Dom. C, IKS. C, ikstack. C, utility. C, and sax. C under the src directory to your project.

3. Remember to add the estlib. Lib library. Otherwise, the program will crash when using malloc.

4. The estlib. Lib file is in the libc directory. Therefore, add it to the MMP 5.

 

Code:

Parsexmll ()
{

_ Partition (kxmlfilename, "C: // food. xml ");
Rfile readfile;
Rfs fs;
FS. Connect ();

Tint err = readfile. Open (FS, kxmlfilename, efileread );
If (Err! = Kerrnone)
{
Readfile. Close ();
FS. Close ();
Return;
}

Tint filesize (0 );
Readfile. Size (filesize );
Hbufc8 * xmldata = hbufc8: newl (filesize );
Tptr8 ptr8 (xmldata-> des ());
Readfile. Read (ptr8 );

Ctextlistboxmodel * model = ilistbox-> model ();
Cdescarray * itemarray = static_cast <cdescarray *> (model-> itemtextarray ());

Tint OK;
IKS * root = iks_tree (char *) xmldata-> des (). PTR (), xmldata-> des (). Length (),
& OK );
If (OK = iks_ OK)
{

IKS * userslist = iks_find (root, "channel ");
IKS * userlist = iks_find (userslist, "item ");
While (userlist)
{
If (iks_type (userlist) = iks_tag)
{
// Name
Char * valuename = iks_find_cdata (userlist, "category ");
Tptrc8 ptrname (unsigned char *) valuename );
Hbufc * bufname = hbufc: newl (ptrname. Length ());
Tptr16 ptrname16 = bufname-> des ();
Cnvutfconverter: converttounicodefromutf8 (ptrname16, ptrname );
Ptrname16.trim ();

// Telephone number
Char * valuemobile = iks_find_cdata (userlist, "title ");
Tptrc8 ptrmobile (unsigned char *) valuemobile );
Hbufc * bufmobile = hbufc: newl (ptrmobile. Length ());
Tptr16 ptrmobile16 = bufmobile-> des ();
Cnvutfconverter: converttounicodefromutf8 (ptrmobile16,
Ptrmobile );
Ptrmobile16.trim ();
_ Substring (kstringheader2, "/T % S/T % s ");
Tbuf <50> buf2;
Buf2.format (kstringheader2 (), & ptrname16, & ptrmobile16 );

Itemarray-> appendl (buf2 );
Delete bufname;
}
Userlist = iks_next (userlist );
}
}
Iks_delete (Root );

Delete xmldata;
Readfile. Close ();
FS. Close ();

Ilistbox-> handleitemadditionl ();
}

 

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.