This article is designed to give oneself in time when needed to find, save every time to Baidu.
1. XML Parsing Library-gdataxml
Reference article: http://blog.csdn.net/tangren03/article/details/7868246
Gdataxml:
(1) gdataxml.h/m file
http://code.google.com/p/gdata-objectivec-client/source/browse/trunk/Source/XMLSupport/
(2) DGataDefines.h GDataTargetNamespace.h File
http://code.google.com/p/gdata-objectivec-client/source/browse/trunk/Source/
Configuration process:
(1). Introduction of Gdataxml (4 files)
<arc mode: Add non-arc annotations to GDATAXML.M-fno-objc-arc
(2). Add System library Libxml2.dylib
(3). Add/USR/INCLUDE/LIBXML2 in Head Search path
(4). Other linker flags Add-LXML2
(5). xml format
==================================
<?xml version= "1.0" encoding= "Utf-8"?>
<Users>
<user id= "001" >
<name>Ryan</name>
<age>24</age>
</User>
<user id= "002" >
<name>Tang</name>
<age>23</age>
</User>
</Users>
==================================
(6). Application
==================================
Get the XML file for the project catalog
NSString *filepath = [[NSBundle mainbundle] pathforresource:@ "Users" oftype:@ "xml"];
NSData *xmldata = [[NSData alloc] initwithcontentsoffile:filepath];
Class using the NSData object.
Gdataxmldocument *doc = [[Gdataxmldocument alloc] Initwithdata:xmldata options:0 Error:nil];
Get root node (Users)
Gdataxmlelement *rootelement = [Doc rootelement];
Gets the node under the root node (User)
Nsarray *users = [rootelement elementsforname:@ "User"];
For (gdataxmlelement *user in users) {
ID attribute of the user node
NSString *userid = [[user attributeforname:@ "id"] stringvalue];
NSLog (@ "User ID is:%@", userId);
Gets the value of the name node
Gdataxmlelement *nameelement = [[User elementsforname:@ "name"] objectatindex:0];
NSString *name = [Nameelement stringvalue];
NSLog (@ "User name is:%@", name);&NBSP;
&NBSP;
//Gets the value of the age node &NBSP;
gdataxmlelement *ageelement = [user elementsforname:@ "Age"] objectatindex:0]; &NBSP;
nsstring *age = [ageelement stringvalue];
NSLog (@ "User age is:%@", age); &NBSP;
NSLog (@ "-------------- -----"); &NBSP;
} &NBSP;