Use and configuration of third-party libraries commonly used in iOS development-gdataxml

Source: Internet
Author: User

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;

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.