gpt4 book ai didi

iphone - NSXMLParser 委托(delegate)处理属性

转载 作者:行者123 更新时间:2023-12-01 18:32:10 24 4
gpt4 key购买 nike

我目前正在尝试让我的解析器委托(delegate)使用自定义 NSObject我已经为我收到的 xml 的属性创建了..

这是正在读入我的解析器委托(delegate)的 XML

<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正确地通过了......这就是我所拥有的那种方法。
- (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)

我特别想帮助我尝试完成第二种方法并让这一切正常工作。

到目前为止,所有的帮助都非常感谢。

最佳答案

对于您正在解析的 xml 文件的类型,

parser:foundCharacters:
永远不会被调用。在这种情况下会调用此委托(delegate)方法:
<mytag>this is the tag content</mytag>

while in your case only attributes are present and no tag content, that is:

<mytag attr1="value1" attr2="value2"></mytag>

As far as the other method:

parser:didEndElement:

它的实现取决于你。例如。如果将元素存储在临时变量中,则此方法可用于将此变量复制到另一个数据结构中。

关于iphone - NSXMLParser 委托(delegate)处理属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7734269/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com