Use and configuration of common third-party libraries in iOS development-GDataXML and ios-gdataxml

Source: Internet
Author: User

Use and configuration of common third-party libraries in iOS development-GDataXML and ios-gdataxml

This article aims to promptly check your future needs, saving you the need to go to baidu every time.

1. xml Parser library-GDataXML
Reference: 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). Introduce GDataXML (4 files)
<Arc mode>. Add a non-arc comment-fno-objc-arc to GDataXML. m.
(2) Add the system library libxml2.dylib
(3) Add/usr/include/libxml2 to the. Head Search Path.
(4) Add-lxml2 to Other linker flags.
(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
========================================
// Obtain the xml file of the project directory
NSString * filePath = [[NSBundle mainBundle] pathForResource: @ "users" ofType: @ "xml"];
NSData * xmlData = [[NSData alloc] initWithContentsOfFile: filePath];

// Use the NSData object for initialization
GDataXMLDocument * doc = [[GDataXMLDocument alloc] initWithData: xmlData options: 0 error: nil];

// Obtain the root node (Users)
GDataXMLElement * rootElement = [doc rootElement];

// Obtain the node (User) under the root node)
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 );

// Obtain the value of the name Node
GDataXMLElement * nameElement = [[user elementsForName: @ "name"] objectAtIndex: 0];
NSString * name = [nameElement stringValue];
NSLog (@ "User name is: % @", name );

// Obtain the value of the age Node
GDataXMLElement * ageElement = [[user elementsForName: @ "age"] objectAtIndex: 0];
NSString * age = [ageElement stringValue];
NSLog (@ "User age is: % @", age );
NSLog (@"-------------------");
}


How does ios parse kissxml to obtain text between nodes?

There are many ways to parse XML in IOS. Previously, I used GDataXML to parse XML files and explained how to use the XML parsing class provided by Google to parse XML files, today, we use another open-source project, KissXML, to parse XML files and introduce open-source projects and configuration items in the same way as in the previous article, download the source code from the KissXML source code and configure it as described in the previous article.
After the configuration is complete, introduce the following header file in AppDelegate. m (I created an Empty project). After compilation, it indicates that the project is successfully introduced and the configuration is ready for use immediately.

[Cpp] view plaincopy
# Import "DDXML. h"
# Import "DDXMLElementAdditions. h"

KissXML supports XPath, which is very convenient to use. For instructions on XPath, refer to this article: XPath tutorial. Here we also use XPath for parsing.

Method In AppDelegate. m:

[Cpp] view plaincopy
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
{
Self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen] bounds];
// Override point for customization after application launch.
Self. window. backgroundColor = [UIColor whiteColor];
[Self. window makeKeyAndVisible];

// Obtain the XML file from the project directory
NSString * path = [[NSBundle mainBundle] pathForResource: @ "users" ofType: @ "xml"];
// Obtain the NSData object and start Parsing
NSData * xmlData = [NSData dataWithContentsOfFile: path];
[Self parseXML: xmlData];

Return YES;
}

XML parsing method:

[Cpp] view plaincopy
-(Void) parseXML :( NSData *) data
{
// Document (KissXML and GDataXML are also DOM-based parsing methods)
DDXMLDocument * xmlDoc = [[DDXMLDocument alloc] initWithData: data options: 0 error: nil];

// Use XPath to locate nodes (XPath is the positioning syntax in XML, similar to the SQL function in the database)
NSArray * users = [xmlDoc nodesForXPath: @ "// User" error: nil];
For (DDXMLEl ...... remaining full text>

Is there no basic learning for ios? Are new graduates suitable for ios development?

1. the development environment is required. You can choose to buy a MAC or install a virtual machine on your computer.
2. The development language is Obj-C. Learn more (5 days)
3. Read the official document about it, mainly to understand the system framework structure and control usage (10 days)
View Programming Guide for iOS
View Controller Programming Guide for iOS
Table View Programming Guide for iOS
Scroll View Programming Guide for iOS
4. Make a simple app for your own needs, or find some open-source apps (5 days)
5. If it is a third-party class library commonly used in IOS, you need to know.
Network, Cache, CoreDate

2.16.apple.com/..x.html
 

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.