私のXMLファイルは:
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<count count="3" />
<spac>
<opt>aa</opt>
<opt>bb</opt>
</spac>
</plist>
NSXML parssrには次のコード行を使用しました:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"spaces"]) {
//Initialize the array.
appDelegate.api = [[NSMutableArray alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
[appDelegate.api addObject:string];
NSLog(@"the count is :%d", [appDelegate.api count]);
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"spaces"])
return;
}
しかし、gdbで次の出力が表示され、理由を理解できません。
2012-06-05 02:20:57.940 XML[490:f803] the count is :0
2012-06-05 02:20:57.942 XML[490:f803] the count is :0
2012-06-05 02:20:57.943 XML[490:f803] the count is :1
2012-06-05 02:20:57.944 XML[490:f803] the count is :2
2012-06-05 02:20:57.945 XML[490:f803] the count is :3
2012-06-05 02:20:57.946 XML[490:f803] the count is :4
2012-06-05 02:20:57.946 XML[490:f803] the count is :5
2012-06-05 02:20:57.948 XML[490:f803] the count is :6
2012-06-05 02:20:57.948 XML[490:f803] the count is :7
2012-06-05 02:20:57.949 XML[490:f803] the count is :8
誰かが私を助けてくれますか?私はObjectiveCを初めて使用します。ありがとうございます。