如何解析此 xml 并检索 iPhone 中的数据 [重复]
Posted
技术标签:
【中文标题】如何解析此 xml 并检索 iPhone 中的数据 [重复]【英文标题】:How to parse this xml and retrieve the data in iPhone [duplicate] 【发布时间】:2013-03-15 09:45:35 【问题描述】:我正在开发一个 iPad 应用程序。我们以 XML 格式获取数据。我使用NSXMLParser
进行解析,所有数据都打印到控制台。如何分别检索值?
另一个问题是如何检查 iPhone 中的内存泄漏?
<Result>
<Movieoftheweek>
<Movie_id>3809</Movie_id>
<Movieoftheweek_img_Url>"http://www.add.com/adogs/11055.jpg</Movieoftheweek_img_Url>
<Movie_Name>Luck</Movie_Name>
<gender>Movie</gender>
</Movieoftheweek>
<Movie_List_in_theater>
<movie_in_theater>
<Movie_id>3809</Movie_id>
<Movie_img_Url>http://www.add.com/adogs/11055.jpg</Movie_img_Url>
<Movie_Name>Luck</Movie_Name>
<gender>Movie</gender>
</movie_in_theater>
<movie_in_theater>
<Movie_id>3809</Movie_id>
<Movie_img_Url>http://www.add.com/adogs/6055.jpg</Movie_img_Url>
<Movie_Name>Luck</Movie_Name>
<gender>Movie</gender>
</movie_in_theater>
<movie_in_theater>
<Movie_id>3809</Movie_id>
<Movie_img_Url>http://www.add.com/adogs/525.jpg</Movie_img_Url>
<Movie_Name>Luck</Movie_Name>
<gender>Movie</gender>
</movie_in_theater>
</Movie_List_in_theater>
<Movie_List_Coming_Soon>
<movie_Coming_Soon>
<Movie_id>3803</Movie_id>
<Movie_img_Url>http://www.add.com/adogs/5000.jpg</Movie_img_Url>
<Movie_Name>Kode</Movie_Name>
<gender>Movie</gender>
</movie_Coming_Soon>
<movie_Coming_Soon>
<Movie_id>3803</Movie_id>
<Movie_img_Url>http://www.add.com/adogs/5900.jpg</Movie_img_Url>
<Movie_Name>Kode</Movie_Name>
<gender>Movie</gender>
</movie_Coming_Soon>
<movie_Coming_Soon>
<Movie_id>3803</Movie_id>
<Movie_img_Url>http://www.add.com/adogs/5500.jpg</Movie_img_Url>
<Movie_Name>Kode</Movie_Name>
<gender>Movie</gender>
</movie_Coming_Soon>
</Movie_List_Coming_Soon>
</Result>
【问题讨论】:
edumobile.org/iphone/iphone-programming-tutorials/… IDK “检查内存泄漏”是如何出现的。正确管理内存,你不会有泄漏,繁荣。 ***.com/questions/1021102/parsing-xml-in-iphone-xcode 使用TBXML进行解析 【参考方案1】:你好,在发布之前做一些 r 和 D 很多帖子都可用,只需检查这个 link 它可能对你有帮助
在你的方法中
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
if([elementName isEqualToString:@"Result"])
//Initialize the array.
arrXMLData = [[NSMutableArray alloc] init];
else if([elementName isEqualToString:@"Movieoftheweek"])
currentElementValue = [[NSMutableString alloc] init];
else if([elementName isEqualToString:@"Movie_List_in_theater"])
currentElementValue = [[NSMutableString alloc] init];
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];
NSLog(@"Processing Value: %@", currentElementValue);
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
if([elementName isEqualToString:@"Result"])
return;
else if([elementName isEqualToString:@"Movieoftheweek"])
[arrXMLData addObject:currentElementValue];
else if([elementName isEqualToString:@"Movie_List_in_theater"])
[arrXMLData addObject:currentElementValue];
[currentElementValue release];
【讨论】:
以上是关于如何解析此 xml 并检索 iPhone 中的数据 [重复]的主要内容,如果未能解决你的问题,请参考以下文章
如何在文档中下载和保存 xml,然后如何从文档中解析 xml 文件?
如何在 Java 中解析包含 XML 的字符串并检索根节点的值?