KissXML范例

[quote]#import "DDXML.h"
#import "DDXMLElementAdditions.h"

//XML File
//<bookcase>
// <book>
// <bookName>My First KissXml Article</bookName>
// <bookAuthor>mOMo</bookAuthor>
// </book>
// <book>
// <bookName>Delete Life</bookName>
// <bookAuthor>Mary</bookAuthor>
// </book>
//</bookcase>

//取得XML檔案實體位置
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"xmlFile" ofType:@"xml"];

//將XML檔案讀出
NSString *xmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

//開始使用KissXML,將讀出的XML字串指定給DDXMLDocument物件
DDXMLDocument *xmlDoc = [[DDXMLDocument alloc]initWithXMLString:xmlString options:0 error:nil];

//釋放
xmlString = nil;

//開始解析
NSArray *children = nil;

//使用XPath取得要走訪的節點
children = [xmlDoc nodesForXPath:@"bookcase/book" error:nil];

//依符合的節點數量走訪
for (int i=0; i < [children count]; i++) {
//建立DDXMLNode
DDXMLNode *child = [children objectAtIndex:i][child childAtIndex:0]stringValue];);
NSLog(@"作者:%@", [[child childAtIndex:1] stringValue];);
}

//釋放
[xmlDoc release];[/quote]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值