Problem Description: The interface returns XML format data, and the node name is actually the same, using the DOM parsing the final Solution
I. File import
1. Download GDataXMLNode.h and GDATAXMLNODE.M files, import project (csdn file download link: http://download.csdn.net/detail/wusangtongxue/9502292)
2. Configure the Environment:
(1) Change into ARC environment (-FNO-OBJC-ARC);
(2) Find the "Paths\header Search Paths" entry and add "/USR/INCLUDE/LIBXML2" to the list;
(3) Find the "Linking\other Linker Flags" entry and add "-LXML2" to the list
3. Import the Sbjson folder to convert the parsed data to a string type
Two. Actual Project
1. XML Format data for Web page printing
2. Import #import "GDataXMLNode.h", parse
-(void) xmlhttprequest{NSString*str =Intranet website; Nsurl*urll =[Nsurl Urlwithstring:str]; Nsmutableurlrequest*request = [Nsmutableurlrequest requestwithurl:urll cachepolicy:nsurlrequestuseprotocolcachepolicy TimeoutInterval:Ten]; //2.[Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlresponse *response, NSData *data, Nserror *connectionerror) {Nserror*errror =Nil; Gdataxmldocument*document = [[Gdataxmldocument alloc]initwithdata:data options:0error:&Errror]; //Get root nodeGdataxmlelement *rootelement =[Document RootElement]; //gets all child nodes loaded into an arrayNsarray *array = [rootelement elementsforname:@"string"]; NSLog (@"Print array:%@", array); NSString*string=[nsstring stringWithFormat:@"%@", array[2]]; Nsrange Startstr= [stringRangeofstring:@"<string>"]; Nsrange End= [stringRangeofstring:@"</string>"]; NSString*sub = [stringSubstringwithrange:nsmakerange (startstr.location+8, end.location-startstr.location-9)]; NSLog (@"Print the truncated string:%@", sub); }];}
Array: Print Arrays: (
"Gdataxmlelement 0x7ff26ad97f10: {type:1 name:string xml:\" <string>610</string>\ "}",
"Gdataxmlelement 0x7ff26ad97cb0: {type:1 name:string xml:\" <string/>\ "}",
"Gdataxmlelement 0x7ff26ad97ce0: {type:1 name:string xml:\" <string>http://192.168.1.1:8080/</string>\ " }",
"Gdataxmlelement 0x7ff26adbb480: {type:1 name:string xml:\" <string/>\ "}"
)
Sub: Print the truncated string: http://192.168.1.1:8080
So we can get nsstring data.
Note : The URL is the intranet, need to be based on their own needs to parse the example here is the XML data of my project, a bit special is the node name is the same
Reference URL: http://www.cnblogs.com/pengyingh/articles/2342164.html
IOS DOM parsing XML format data