解析iPhone的XML(aMule下载/搜索结果) [英] Parsing XML for iPhone (aMule downloads/ search results)
问题描述
我目前正在开发通过iPhone控制服务器的aMule状态的软件,
i创建了一个套接字,该套接字吐出了应该解析的xml,但是由于NSXMLParser是事件驱动的,所以在理解其工作方式方面存在问题...
我想到了这种XML结构,如果您有更好的结构化方法的想法,请告诉我! :D
I am currently working on a software to control aMule status of my server through the iPhone, i created a socket that spits out xml which should be parsed out, but because NSXMLParser is event-drive, i'm having problems in understanding how this could work... I thought of this type of XML structure, if you have ideas of a better way to structure it please tell me!! :D
<root type="donwloads"> <-- specifies downloads or search results
<file name="Ubuntu_9_10.iso" status="[11,6%]" />
<file name="Fedora 12.iso" status="[56,2%]" />
</root>
我在想的是,因为我想将其放在表格视图中,所以我很可能需要一个NSMutableArray,根据结果有很多NSDictionaries,每个字典应该是一个文件..你们建议什么?我应该如何处理这种情况?
What i was thinking is, as i want to put this in a tableview, most probably i will need a NSMutableArray with lots of NSDictionaries based on the results, every dict should be a file.. what do you guys propose?? how should i handle this situation?
谢谢
推荐答案
感谢您的答案很多:D幸运的是:D
生病了我十分钟后,我解决了问题:
Thanks a lot for your answers :D fortunately i resolved the problem 10 minutes after :D ill post what i did:
XML:
<root>
<downloads>
<file type="text" name="fdsdf" />
<file type="text" name="sdfsdfssds" />
</downloads>
</root>
NSXMLParser代表:
NSXMLParser delegates:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{
if([elementName isEqualToString:@"downloads"] || [elementName isEqualToString:@"results"]){
NSLog(@"starting or downloads or results");
if(xmlArray){
xmlArray= nil;
}
self.xmlArray= [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:@"file"]){
NSLog(@"found file...");
[self.xmlArray addObject:attributeDict];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if([elementName isEqualToString:@"downloads"] || [elementName isEqualToString:@"results"]){
if([elementName isEqualToString:@"downloads"]){
NSLog(@"downloads found: %@... reloading table", xmlArray);
}
}
}
我希望这会有所帮助有我同样问题的人:D
I hope this can possibly help someone which has my same problem :D
这篇关于解析iPhone的XML(aMule下载/搜索结果)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!