Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone XML属性传递问题_Iphone_Objective C_Attributes_Xml Parsing - Fatal编程技术网

Iphone XML属性传递问题

Iphone XML属性传递问题,iphone,objective-c,attributes,xml-parsing,Iphone,Objective C,Attributes,Xml Parsing,我必须解析一个xml,该xml的链接是 可能需要解析的是: -(IBAction)autoLoginBtn{ NSString *url=[NSString stringWithFormat: @"http://qasimshah.sitesled.com/schedule.xml"]; [self parseXMLFileAtURL:url]; } - (void)parseXMLFileAtURL:(NSString *)URL { xmlDataArr

我必须解析一个xml,该xml的链接是

可能需要解析的是:

-(IBAction)autoLoginBtn{

    NSString *url=[NSString stringWithFormat: @"http://qasimshah.sitesled.com/schedule.xml"];

    [self parseXMLFileAtURL:url];

}
- (void)parseXMLFileAtURL:(NSString *)URL
{   
    xmlDataArray1 = [[NSMutableArray alloc] init];

    //you must then convert the path to a proper NSURL or it won't work
    NSURL *xmlURL = [NSURL URLWithString:URL];

    // here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error
    // this may be necessary only for the toolchain
    NSXMLParser *rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];

    // Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
    [rssParser setDelegate:self];

    // Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
    [rssParser setShouldProcessNamespaces:NO];
    [rssParser setShouldReportNamespacePrefixes:NO];
    [rssParser setShouldResolveExternalEntities:NO];

    [rssParser parse];

}
-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
    NSLog(@"Error on XML Parse: %@", [parseError localizedDescription] );
}


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{            
    //NSLog(@"found this element: %@", elementName);
    currentElement = [elementName copy];
    if ([elementName isEqualToString:@"Sports"]) {
        // clear out our story item caches...
        item = [[NSMutableDictionary alloc] init];
        currentTitle = [[NSMutableString alloc] init];
    }

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{     
    if ([elementName isEqualToString:@"Sport"]) {

        [item setObject:currentTitle forKey:@"id"];

        [xmlDataArray1 addObject:[item copy]];
        NSLog(@"id: %@", currentTitle);
    }

}
但当我试图获取'id'或
name
parser时,会检测到它,但不会返回它的值。
那么如何获取其值呢?

您应该在“attributeDict”中获取属性值


您只是在引用元素…

您应该在“attributeDict”中获取属性值


您只是在引用元素…

试试这个。你可以得到所有这样的值

        - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
          namespaceURI:(NSString *)namespaceURI 
         qualifiedName:(NSString *)qName 
            attributes:(NSDictionary *)attributeDict
        {   
            if([elementName isEqualToString:@"Sport"])
            {
                NSString *s = [NSString stringWithFormat:@"%@",elementName];
                NSLog(@"%@",s);

                NSString *s1 =[NSString stringWithFormat:@"%@",[attributeDict valueForKey:@"id"]];
                NSLog(@"%@",s1);

                NSString *s2 =[NSString stringWithFormat:@"%@",[attributeDict valueForKey:@"name"]];
                NSLog(@"%@",s2);

                NSString *s3 =[NSString stringWithFormat:@"%@",[attributeDict valueForKey:@"abbr"]];
                NSLog(@"%@",s3);
            }
        }

试试这个。你可以得到所有这样的值

        - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
          namespaceURI:(NSString *)namespaceURI 
         qualifiedName:(NSString *)qName 
            attributes:(NSDictionary *)attributeDict
        {   
            if([elementName isEqualToString:@"Sport"])
            {
                NSString *s = [NSString stringWithFormat:@"%@",elementName];
                NSLog(@"%@",s);

                NSString *s1 =[NSString stringWithFormat:@"%@",[attributeDict valueForKey:@"id"]];
                NSLog(@"%@",s1);

                NSString *s2 =[NSString stringWithFormat:@"%@",[attributeDict valueForKey:@"name"]];
                NSLog(@"%@",s2);

                NSString *s3 =[NSString stringWithFormat:@"%@",[attributeDict valueForKey:@"abbr"]];
                NSLog(@"%@",s3);
            }
        }

didStartElement:
中检查“运动”,但在
didEndElement:
中检查“运动”…

didStartElement:
中检查“运动”,但在
didEndElement:
中检查“运动”