<root>
<name value="wusj"/>
<age>24</age>
</root>
对此xml文件进行解析
NSString *xmlPath = [[NSBundlemainBundle] pathForResource:@"test"ofType:@"xml"]; NSString *xmlString = [NSStringstringWithContentsOfFile:xmlPath encoding:NSUTF8StringEncodingerror:nil]; GDataXMLDocument *xmlDoc = [[GDataXMLDocumentalloc] initWithXMLString:xmlString options:0error:nil]; GDataXMLElement *xmlEle = [xmlDoc rootElement]; NSArray *array = [xmlEle children]; NSLog(@"count : %d", [array count]); for (int i = 0; i < [array count]; i++) { GDataXMLElement *ele = [array objectAtIndex:i]; // 根据标签名判断 if ([[ele name] isEqualToString:@"name"]) { // 读标签里面的属性 NSLog(@"name --> %@", [[ele attributeForName:@"value"] stringValue]); } else { // 直接读标签间的String NSLog(@"age --> %@", [ele stringValue]); } }