Gdata XML parsing configuration and simple use, gdataxml parsing Configuration

Source: Internet
Author: User

Gdata XML parsing configuration and simple use, gdataxml parsing Configuration

Import libxml2, use third-party AFNetworking network requests, third-party XML parsing GData

Search for the configuration Build Settings required by GData, and add the following

-Fno-objc-ARC must be added for arc.

First, find an xml URL and use AFNetworking to request NSData.

#define HTTP_URL_GET @"http://lab.hudong.com/ipad/zutujingxuan.xml"
-(Void) getRequest {AFHTTPRequestOperationManager * manager = [[AFHTTPRequestOperationManager alloc] init]; // return data parsing manager. responseSerializer = [Response serializer]; // response responseObject is the object parsed by Jesus (which may be a dictionary) // response responseObject is the NSXMLPareser object // AFHTTPRequestOperationManager responseObject is NSData [manager GET: HTTP_URL_GET parameters: nil success: ^ (AFHTTPRequestOperation * operation, id responseObject) {NSLog (@ "% @", responseObject); // NSXMLParser [self xml: responseObject];} failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {NSLog (@ "error: % @. ", error. localizedDescription);}];}

First open Firefox to view the xml hierarchy (copy the URL to open it on Firefox)

Use GData parsing to remember layer-by-layer Parsing

-(Void) xml :( NSData *) data {// create a parsing object GDataXMLDocument * document = [[GDataXMLDocument alloc] initWithData: data options: 0 error: nil]; // obtain the root node GDataXMLElement * rootElement = document. rootElement; NSLog (@ "name: % @, stringvaule: % @", rootElement. name, rootElement. stringValue); GDataXMLElement * channeName = [rootElement elementsForName: @ "channelName"]. firstObject; NSLog (@ "% @ --- % @", channeName. name, channeName. stringValue); // retrieve multiple groups // docInfo directly skips the previous subnode and knows the subnode corresponding to the obtained name // NSArray * docInfos = [rootEiement nodesForXPath: @ "// docInfo" error: nil] NSArray * docInfos = [[rootElement elementsForName: @ "docList"]. firstObject elementsForName: @ "docInfo"]; for (GDataXMLElement * docInfoElement in docInfos) {limit * dic = [NSMutableDictionary dictionary]; for (GDataXMLElement * elment in [docInfoElement children]) {[dic setObject: elment. stringValue forKey: elment. name];} [_ allInfos addObject: dic];} NSLog (@ "% @", _ allInfos );}

Finally, a global NSMutableArray is used to receive printing ,~

Related 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.