微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将XML数据解析为NSMutableArray iOS – iPhone

这是XML数据:
<Categorys> 
    <Category>  
        <categoryId>25</categoryId>  
            <categoryName>My Photos</categoryName>                                  
                <categoryDescription>Description</categoryDescription>      
            <categoryIconPath>7.jpg</categoryIconPath>      
            <userId>2</userId>  
            <categoryStatus>ON</categoryStatus>  
        <publicPrivate>Private</publicPrivate>
    </Category>
......more categories
<Categorys>

在这里,我想得到< categoryName>我的NSMutableArray categList中的值.

我使用的代码是:

- (void)parser:(NSXMLParser *)parser didStartElement:(Nsstring *)elementName namespaceURI:(Nsstring *)namespaceURI
                                       qualifiedname:(Nsstring *)qualifiedname 
                                          attributes:(NSDictionary*)attributeDict {

    if ( [elementName isEqualToString:@"categList"]) {
        // addresses is an NSMutableArray instance variable
        if (!categList)
            categList = [[NSMutableArray alloc] init];
        return;
    }

    NSLog(@"StartedElement %@",elementName);

    element = [NSMutableString string];

}


- (void)parser:(NSXMLParser *)parser foundCharacters:(Nsstring *)string {

    if(element == nil)

        element = [[NSMutableString alloc] init];

        [element appendString:string];

}

- (void)parser:(NSXMLParser *)parser didEndElement:(Nsstring *)elementName 
                                      namespaceURI:(Nsstring *)namespaceURI
                                     qualifiedname:(Nsstring *)qName {

    NSLog(@"Found an element named: %@ with a value of: %@",elementName,element);

    if ([elementName isEqualToString:@"categoryName"]) {

        NSLog(@"\n\n\nfound::::::::::::::: %@",element);

        category = element;

        NSLog(@"category:::: %@",category);

    }

    [categList addobject:element];
    NSLog(@"categList*************** %@",categList);
}

但我没有在我的NSMutableArray categList中获取类别名称

我的代码有什么问题?

原文地址:https://www.jb51.cc/xml/293027.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。