KissXmlを使用してxmlを解析する


プロジェクト内のファイルtextについて.xmlの内容は次のとおりです.


Angel
Parser xml
test Parser Xml With Kiss Xml

kissxml解析xmlを使用する必要があります
まずtextを取得する.xmlのurl
NSString *path = [[NSBundle mainBundle] pathForResource:@"xmlData"ofType:@"xml"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
次にkissxmlを使用してxmlを解析し、
-(void)parsedDataFromData:(NSData *)data{
	[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
	DDXMLDocument *doc = [[DDXMLDocument alloc] initWithData:data options:0 error:nil];
	
	/////  
	NSArray *items = [doc nodesForXPath:kXML error:nil];
	
	for (DDXMLElement *obj in items) {
		xmlData *data = [[xmlData alloc] init];
		
		DDXMLElement *aUser = [obj elementForName:KUSER];
		if(aUser)
			data.user = aUser.stringValue;
		DDXMLElement *aTitle = [obj elementForName:KTITLE];
		if(aTitle)
			data.title = aTitle.stringValue;
		DDXMLElement *content = [obj elementForName:KCONTENT];
		if(content)
			data.content = content.stringValue;
		NSDictionary *XmlDictionary;
		XmlDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
						 data.user,@"kUsers",
						 data.title,@"kTitles",
						 data.content,@"kContents",
						 nil];
		[self performSelectorInBackground:@selector(parsedXml:) withObject:XmlDictionary];
		[data release];
	}
	[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
	[doc release];
}
KissXml解析xml