XML 文件代码:
<Books>
<Book id="1" isbn="123456">
<name>Let Us C</name>
<authors>
<author>Yashwant Kanetkar</author>
<author>ABC</author>
</authors>
<price>250.00</price>
</Book>
<Book id="2" isbn="345678">
<name>Programing With C++</name>
<authors>
<author>Balaguruswamy</author>
<author>XYZ</author>
</authors>
<price>400.00</price>
</Book>
<Book id="3" isbn="789012">
<name>Professional iPhone and iPad Application Development</name>
<authors>
<author>Gene Backlin</author>
<author>QWE</author>
</authors>
<price>550.00</price>
</Book>
<Book id="4" isbn="901234">
<name>Beginning iOS 4 Application Development</name>
<authors>
<author>Wei-Meng Lee</author>
<author>IOP</author>
</authors>
<price>500.00</price>
</Book>
</Books>
谁能帮我解决这个问题?
我正在使用这段代码:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"Books"])
{
appDelegate.books = [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:@"Book"])
{
aBook = [[Book alloc] init];
aBook.bookID = [[attributeDict objectForKey:@"id"] integerValue];
aBook.isbn = [[attributeDict objectForKey:@"isbn"] integerValue];
NSLog(@"Reading isbn value : %@", aBook.isbn);
NSLog(@"Reading id value :%i", aBook.bookID);
}
NSLog(@"Processing Element: %@", elementName);
}