有两个选择。 如果你继续使用<条码>NSXMLDocment,并且有一部电影内容的,你可以这样做:
if ([movieNode kind] == NSXMLElementKind)
{
NSXMLElement *movieElement = (NSXMLElement *) movieNode;
NSArray *attributes = [movieElement attributes];
for (NSXMLNode *attribute in attributes)
{
NSLog (@"%@ = %@", [attribute name], [attribute stringValue]);
}
}
否则,你可以改用NSXMLParser
。 这是一项由教区推动的活动,当其教职人员(除别的外)混杂时,会通知一名代表。 http://developer.apple.com/mac/library/documentation/coa/vis/NSXMLParserDelegate_ Protocol/Reference/Reference.html#/apple_ref/occ/intfm/NSXParserDelegate/parser:didStartElement:namespaceURI:standardName:attributes:"rel=“noreferer”> :parser:didartElement: 姓名:空间UR
- (void) loadXMLFile
{
NSXMLParser *parser = [NSXMLParser parserWithContentsOfURL:@"file:///Users/jkem/test.xml"];
[parser setDelegate:self];
[parser parse];
}
// ... later ...
- (void) parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"movie"])
{
NSLog (@"%@", [attributeDict objectForKey:@"a"]);
NSLog (@"%d", [[attributeDict objectForKey:@"b"] intValue]);
}
}