gpt4 book ai didi

objective-c - 解析空节点时 iPhone 应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 04:34:01 25 4
gpt4 key购买 nike

我正在尝试解析 xml,如果 xml feed 中有空节点,应用程序就会崩溃。这可能是什么原因?

编辑我的 xml 看起来像这样

<Sponsors>
<Sponsor>
<Name>name...</Name>
<About>blah...blah...blah</About>
<Website>http://test.com</Website>
<LogoImage>someImage.jpg</LogoImage>
<smallIcon>someImage.jpg</smallIcon>
<Area/>
<BannerImage/>//->>>this node is empty//
</Sponsor>
</Sponsors>

我正在像这样使用 NSXML 解析器。

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(nil != self.currentsponsorElement){
[self.currentsponsorElement appendString:string];
}

}

最佳答案

试试这个:-

在 didStartElement 中使用以下代码:-

- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{

if ([elementName isEqualToString:@"Sponsor"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init]; //declared in .h
}
recordResults = YES;
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSMutableString *)string {

if (string != nil) {
[results setString:@""];
[results appendString: string];
NSLog(@"foundResults: %@",results);
}

}

关于objective-c - 解析空节点时 iPhone 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11291159/

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