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 ,~