Web service and XML data parsing for iOS Development Network chapter

Source: Internet
Author: User

Shimen the main contribution, respect the work of the author, please do not reprint.

If the article is helpful to you, you are welcome to donate to the author and support the Shimen master. The donation amount is arbitrary, heavy in the mind ^_^

I want to donate: Click Donate

Cocos2d-x source code Download: Dot I teleport

Games Official Download:HTTP://DWZ.CN/RWTJL

Game video preview:http://dwz.cn/RzHHd

Game Development Blog:Http://dwz.cn/RzJzI

Game Source code transfer : Http://dwz.cn/Nret1


Use Web service to get the most common form of server data in communication between iphone and back-office systems.

In the Web service communication. Data interchange formats typically use XML data, and XML data is a common form of software development.

Therefore, XML parsing is also a basic skill that must be mastered in project development.

This article provides an XML data parsing class Simplexmlparser,

The characteristics of this class will parse the XML data into a database record form, and the data is parsed and saved in Nsarray.

Each element of the array corresponds to a database record, and each record is a nsdictionary consisting of database fields and values.


1. Interface definition

@interface simplexmlparser:nsobject{nsstring *currentpropertyname; Nsmutablestring *currentdata; BOOL Contenterror; NSString *faultname; NSString *faultname2; Nsmutabledata *webdata; Nsmutablearray *themainstack; Nsmutablearray *currentdatastack; Nsxmlparser *parser; NSString *recordhead; Nsinteger Sectioncount; BOOL Beginrecord; Nsmutablestring *currentcharacters; Nsmutabledictionary *parsedresponsedictionary; NSString *parseelementpath;} -(ID) init;-(void) InitData: (Nsmutabledata *) data;-(void) Parse: (nsstring*) head;-(BOOL) iscontentfault;-(Nsinteger) getrecordcount;-(nsdictionary*) Getrecordatindex: (Nsinteger) idx;-(nsmutablearray*) getrecordlists;

2. Use

Nsmutabledata *webdata; Simplexmlparser *thisparser = [[Simplexmlparser alloc] initwithdata:webdata]; NSString *recordhead  = @ "User"; [ Thisparser Parse:recordhead];

The parsed database record is saved in the Recordstack variable of the parser object, first getting the number of record bars, and then traversing each record.

Nsinteger i = 0, nresult = [Thisparser getrecordcount];for (i = 0; i < Nresult; i++) {nsdictionary *recorddict = [ThisPar Ser getrecordatindex:i]; Nsdictionary *tempdic = [recorddict objectforkey:@ "Tempdic"]; NSString *value = [Tempdic objectforkey:@ "value"];}


Simplexmlparser class : click I download

If no points, the blog following reply to leave an email address.


Shimen the main contribution, respect the work of the author, please do not reprint.

If the article is helpful to you, you are welcome to donate to the author, support the Shimen, donate any amount, ^_^

I want to donate: Click Donate

Cocos2d-x source code Download: Dot I teleport

Games Official Download:HTTP://DWZ.CN/RWTJL

Game video preview:http://dwz.cn/RzHHd

Game Development Blog:Http://dwz.cn/RzJzI

Game Source code transfer : Http://dwz.cn/Nret1

Parsing Web service and XML data for the iOS Development Network article

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.