NSXMLParser委托处理属性 [英] NSXMLParser delegates Handling Attributes

查看:74
本文介绍了NSXMLParser委托处理属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试让解析器委托与为接收的xml属性创建的自定义 NSObject 一起使用。.

I am currently trying to get my parser delegates to work with a custom NSObject I have created for the attributes of the xml I am receiving..

这是正在读取到我的解析器委托中的XML

This is the XML that is being read in to my parser delegates

<Rows>
<Row SKATERID="706" MANUFACTURER="GAZ" ISFACT="F" ISSKATE="F"/>
<Row SKATERID="318" MANUFACTURER="MAN" ISFACT="F" ISSKATE="T"/>
//...
</Rows>

这就是我的 -parser:didStartElement:namespaceURI:qualifiedName的内容:attributes:方法:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if ( [elementName isEqualToString:@"Row"]) {

        manufactureNSObject = [[ManufactureNSObject alloc] init];

        manufactureNSObject.ISFACT = [attributeDict objectForKey:@"ISFACT"];
         manufactureNSObject.ISSKATE = [attributeDict objectForKey:@"ISSKATE"];
         manufactureNSObject.MANUFACTURER = [attributeDict objectForKey:@"MANUFACTURER"];
         manufactureNSObject.SKATERID = [attributeDict objectForKey:@"SKATERID"];

        NSLog(@"%@ %@ %@ %@", manufactureNSObject.ISFACT, manufactureNSObject.ISSKATE, manufactureNSObject.MANUFACTURER, manufactureNSObject.SKATERID);
    }    
} 

我的 NSLog 会打印出所有正确的值,接下来我会遇到的是
-parser:didEndElement:namespaceURI:qualifiedName:方法,除了 didEndElement 之外,其他所有东西都无法正确通过...这就是我对这种方法的要求。

My NSLog prints out all of the correct values fine, the next part that I am stuck on is the - parser:didEndElement:namespaceURI:qualifiedName: method, nothing apart from the didEndElement is coming through correctly... this is what I have for that method.

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    NSLog(@"%@", elementName);
    NSLog(@"%@", namespaceURI);
    NSLog(@"%@", qName);
}

这是我从 NSLog输出的结果 s。

2011-10-13 10:04:16.529 Code[52605:207] F F GAZ 76
2011-10-13 10:04:16.531 Code[52605:207] Row
2011-10-13 10:04:16.535 Code[52605:207] (null)
2011-10-13 10:04:16.537 Code[52605:207] (null)
2011-10-13 10:04:16.537 Code[52605:207] F T MAN 38
2011-10-13 10:04:16.538 Code[52605:207] Row
2011-10-13 10:04:16.539 Code[52605:207] (null)
2011-10-13 10:04:16.540 Code[52605:207] (null)

我特别想帮助您完成第二种方法并使其正常工作。

I specifically would like help with trying to complete the second method and get this all working correctly.

到目前为止,所有帮助都得到了极大的赞赏。

All the help so far has been greatly appreciated.

推荐答案

以防万一有人将来查看此页面,我已经找到了解决方法

Just incase someone checks this page out in the future I have found out how to do this

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@",@"MANUFACTURER",cell.textLabel.text];
            NSArray *filterArray = [myDataArray filteredArrayUsingPredicate:predicate];
            [[self delegate] setManufactureSearchFields:filterArray withIndexPath:indexPath]; //This is where I pass the value back to the mainview

谓词是您的朋友。还擅长从字典中隔离所需的值...

predicate are your friend.. and they are also good at isolating the values you want from a dictionary...

BOOM!

这篇关于NSXMLParser委托处理属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆