为NSXMLParser创建正确的路径

时间:2016-08-26 17:23:30

标签: objective-c directory nsxmlparser

我正在尝试构建xml文件的路径,然后从该文件中提取数据。我的fullPath和xmlPath应该是一样的。 fullPath显示正确的完整路径,但xmlPath显示(null)。我需要xmlPath才能工作,这样我就可以从我的xml文件中提取数据。

- (void)parseXMLFile {

NSString *beginning = @"/Users/";

NSString *user =  NSUserName();


NSString *docPath =@"/localPath.../.../...";


NSString *combined = [NSString stringWithFormat:@"%@%@%@", beginning, user, docPath];

NSLog(@"Path: %@", combined);

NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:combined];

NSString *filename;



while ((filename = [dirEnum nextObject])) {

    if([[filename pathExtension] compare: @"moti"] == NSOrderedSame ||
       [[filename pathExtension] compare: @"moef"] == NSOrderedSame ||
       [[filename pathExtension] compare: @"motr"] == NSOrderedSame ||
       [[filename pathExtension] compare: @"motn"] == NSOrderedSame) {



        NSString *fullPath = [NSString stringWithFormat:@"%@%@", combined, filename];


        NSURL *xmlPath = [[NSBundle mainBundle] URLForResource:(fullPath)
                                                 withExtension:@"moef"];

        self.parser = [[NSXMLParser alloc] initWithContentsOfURL:xmlPath];
        self.parser.delegate = self;
        [self.parser parse];

        NSLog(@"FULL PATH: %@",fullPath);

        NSLog(@"XML PATH: %@", xmlPath);
    }
}

}

0 个答案:

没有答案