analysieren Ich bin ein Anfänger in Ziel C, ich möchte eine XML-Datei von URL analysieren, ich fand einige Beispielcode über NSXMLPARSER und ich schreibe diesen Code, aber es funktioniert nicht.Ich kann XML nicht von URL auf Ziel c
bitte helfen Sie mir.
meine XML-Datei ist:
<list>
<first>apple</first>
</list>
... Mein ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <NSXMLParserDelegate> {
}
@property (weak, nonatomic) IBOutlet UITextView *myTextField;
@end
... Mein ViewController.m
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController @synthesize myTextField;
- (void)parseXMLFileAtURL:(NSString *)URL {
NSURL * xmlURL = [NSURL URLWithString:URL];
NSXMLParser * rssparser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[rssparser setDelegate:self];
[rssparser parse];
}
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary*)attributeDict {
if ([elementName isEqualToString:@"list"]) {
// clear out our story item caches...
myTextField.text = [attributeDict objectForKey:@"first"];
}
}
- (void)viewDidLoad {
NSString * path = @"http://example.com";
[self parseXMLFileAtURL:path];
[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload {
[self setMyTextField:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
Ich habe nicht verstanden - wie rufe ich es von meinem UiViewController auf, wenn ich eine neue Zeichenfolge analysieren und zurückgeben muss? – Dejell