-7

我正在开发一个 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>
4

1 回答 1

1

您好,在发布之前做一些 r 和 D 很多帖子都可用,只需查看此链接,它可能会对您有所帮助

在你的方法中

- (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];
   }
于 2013-03-15T10:31:17.827 回答