Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the systematic methods of XML data parsing

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the systematic methods of XML data parsing. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

XML is a self-describing data exchange format. Is a very important data exchange format, which has been used in various computer languages for many years. XML is similar to HTML, has a pair of tags, the format is more rigorous than HTML, a beginning, an end.

The content of the analysis is:

Zhang San 123456 Xiao Zhang 1111111111 Zhang San 2222222 Xiao Si Li Si is a good student Zhang San 88888888 Primary five 1234567890

The data has been read and stored in data beforehand.

Create a class that inherits from NSObject and names it userInfo

@ property (nonatomic,copy) NSString * uID;@property (nonatomic,copy) NSString * name;@property (nonatomic,copy) NSString * password;@property (nonatomic,copy) NSString * nickname;@property (nonatomic,copy) NSString * description

Create another class, which is also inherited from NSObject and named userParser, to read the xml file.

UserParser.h

# import # import "user.h" @ interface userParser: array of NSObject// storage information @ property (nonatomic,retain) NSMutableArray * array;// instance @ property (nonatomic,retain) user * people;// create string save information @ property (nonatomic,copy) NSMutableString * buffer;// read xml file-(void) parserWithString: (NSString *) string;@end

Userparser.m

# import "userParser.h" @ implementation userParser- (void) parserWithString: (NSString *) string {/ / use system XML parsing method NSXMLParser * parser= [[NSXMLParser alloc] initWithData: [string dataUsingEncoding:NSUTF8StringEncoding]]; / / set proxy parser.delegate=self; / / start parsing [parser parse];} # pragma mark-NSXMLParserDelegate---// start parsing-(void) parserDidStartDocument: (NSXMLParser *) parser {NSLog (@ "it begin") } / / end of parsing-(void) parserDidEndDocument: (NSXMLParser *) parser {NSLog (@ "it is over"); for (int iTuno; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report