iphoen do not have NSXML* librarys, wo can instead with
touchxml,TouchXML is a lightweight replacement for Cocoa’s NSXMLcluster
of classes. It is based on the commonly available Open Source libxml2
library.
1. Getting the TouchXML Libraries
you can dowload TouchXML library
from TouchCode
2. add TouchXML Libraries to your project
find the guid here TouchXMLHowTo
3. use TouchXML in your project
#import "TouchXML.h"
// grabRSSFeed function that takes a string (blogAddress) as a parameter and
// fills the global blogEntries with the entries
-(void) grabRSSFeed:(NSString *)blogAddress {
// Initialize the blogEntries MutableArray that we declared in the header
blogEntries = [[NSMutableArray alloc] init];
// Convert the supplied URL string into a usable URL object
NSURL *url = [NSURL URLWithString: blogAddress];
// Create a new rssParser object based on the TouchXML "CXMLDocument" class, this is the
// object that actually grabs and processes the RSS data
CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease];
// Create a new Array object to be used with the looping of the results from the rssParser
NSArray *resultNodes = NULL;
// Set the resultNodes Array to contain an object for every instance of an node in our RSS feed
resultNodes = [rssParser nodesForXPath:@"//item" error:nil];
// Loop through the resultNodes to access each items actual data
for (CXMLElement *resultElement in resultNodes) {
// Create a temporary MutableDictionary to store the items fields in, which will eventually end up in blogEntries
NSMutableDictionary *blogItem = [[NSMutableDictionary alloc] init];
// Create a counter variable as type "int"
int counter;
// Loop through the children of the current node
for(counter = 0; counter < [resultElement childCount]; counter++) {
// Add each field to the blogItem Dictionary with the node name as key and node value as the value
[blogItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];
}
// Add the blogItem to the global blogEntries Array so that the view can access it.
[blogEntries addObject:[blogItem copy]];
}
}
分享到:
相关推荐
使用TouchXML在iPhone开发、iPad开发中实现XML_Parser
1、TouchXML资源包 2、在cocos2d 2.0,XCode 4.3.3环境下配置TouchXML,详图亲测。 3、TouchXML实例解析。
iOS的XML解析库 TouchXML ,TouchXML 是使用 Objective-C 编写的 XML 解析器,适合在 iOS 和 Mac...
Welcome to Advanced iOS 4 Programming, a text that targets the development of mobile applications on devices (such as the iPhone, iPad, and iPod touch) running the iOS 4 operating system. This text ...
GDataXML,TinyXML,KissXML,TouchXML,TBXML多种xml解析例子,不多说需要的自己下来看看吧!
Xml解析源代码,把TouchXML文件夹copy到工程中,具体操作看一下转载的文章
在iPhone开发中,XML的解析有很多选择,iOS SDK提供了NSXMLParser和libxml2两个类库,另外还有很多第三方类库可选,例如TBXML、TouchXML、KissXML、TinyXML和GDataXML。问题是应该选择哪一个呢? 解析 XML 通常有两...
用ios5.1做的英汉互译软件,有单词本功能,用storyboard做的,sqlite存储数据,详细见文档