我正在开发一款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>
答案 0 :(得分: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];
}