解析XML导致错误 [英] Parsing XML causes Error

查看:210
本文介绍了解析XML导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我的英语不好.我来自德国,在解析xml文件时遇到一些问题.我使用的是最新版本的iOS SDK,包括Xcode.

Sorry for my bad English. I'm from Germany and have some problems with parsing my xml file. I use the latest version of the iOS SDK, including Xcode.

解析我的xml文件会导致一个众所周知的错误,称为在非结构或联合的情况下请求成员'Slices'"

Parsing my xml file causes a well known error, called "Requesting for member 'Slices' in something not a structure or union"

似乎我忘记了一些东西,所以初始化了Delgegate类吗? 如果有人可以帮助我解决问题,那就太好了. 这是我得到的唯一错误... narrf ..

Seems that I have forgotten something, initializing my Delgegate Class ? Would be great if someone could help me through. It's the only error I Get... narrf..

以下是与该问题相关的一些代码:

Here is some of the code, relevant for this problem:

我的XMLParser .h文件

My XMLParser .h File

#import <UIKit/UIKit.h>

@class XMLAppDelegate, Slice;

@interface XMLParser : NSObject <NSXMLParserDelegate>{

    NSMutableString *currentElementValue;

    XMLAppDelegate *appDelegate;
    Slice *aSlice; 
}

- (XMLParser *) initXMLParser;

@end

.m文件的某些部分显示了错误:

And here some parts of the .m File which shows the error:

#import "XMLParser.h"
#import "XMLAppDelegate.h"
#import "Slice.h"

@implementation XMLParser

- (XMLParser *) initXMLParser { 
    [super init];
    appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];
    return self;
}

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

    if([elementName isEqualToString:@"Channel"]) {
        //Initialize the array.
        appDelegate.slices = [[NSMutableArray alloc] init];
    }
    else if([elementName isEqualToString:@"Slice"]) {

        //Initialize the slice.
        aSlice = [[Slice alloc] init];

        //Extract the attribute here.
        aSlice.sliceID = [[attributeDict objectForKey:@"id"] integerValue];

        NSLog(@"Reading id value :%i", aSlice.sliceID);
    }

    NSLog(@"Processing Element: %@", elementName);
}

我尝试使用委托的slices数组后出现错误.

The error shows up after I try to use the slices array of my delegate.

如果有人知道该怎么办,那将是很好的, 这个小东西让我恶心. ^^

Would be great if someone knows what to do, this little thing makes me sick. ^^

推荐答案

解析XML文件没有任何作用,因为您还没走那么远.您的程序仅在运行时才解析XML.您的代码尚未运行,因为它无法编译.

Parsing the XML file didn't do anything, because you haven't gotten that far. Your program will only parse XML when it runs; your code has not run yet, because it does not compile.

该错误在编译中(这就是为什么您在Build Results中看到它的原因),并且是一种语法错误:您试图使用一个编译器无法识别的名称,该名称对于您使用它的地方无效

The error is in compilation (which is why you're seeing it in Build Results), and is a syntax error: You have tried to use a name that the compiler does not recognize as valid for the place where you used it.

特别是:

        appDelegate.slices = [[NSMutableArray alloc] init];

编译器不知道appDelegate具有slices属性;因此,它依赖于其C根,并抱怨您正在尝试对不是结构的对象进行结构访问.您在代码中显示已导入AppDelegate类的标头,因此问题必须是您没有在该类的@interface中声明slices属性.

The compiler doesn't know that appDelegate has a slices property; as such, it falls back on its C roots and complains that you're trying to do a structure access to something that isn't a structure. You show in your code that you imported the header for the AppDelegate class, so the problem must be that you didn't declare the slices property in that class's @interface.

这篇关于解析XML导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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