KissXML范例
  ZiD8n4X6vX1N 2023年11月13日 25 0
[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]

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月13日 0

暂无评论

推荐阅读
  ZiD8n4X6vX1N   2023年11月13日   26   0   0 xml#import
  ZiD8n4X6vX1N   2023年11月13日   26   0   0 ciui#import
  XecrWlEIV3Co   2023年11月13日   24   0   0 xmljavaTestjBPM事件
  sX9JkgY3DY86   2023年11月13日   28   0   0 xmlideandroid
ZiD8n4X6vX1N