如何解析iphone中xml页面的第二个子节点
我是iphone开发新手,我想解析YouTube XML页面,检索其内容并显示在RSS提要中 我的xml页面是如何解析iphone中xml页面的第二个子节点,iphone,objective-c,xml-parsing,Iphone,Objective C,Xml Parsing,我是iphone开发新手,我想解析YouTube XML页面,检索其内容并显示在RSS提要中 我的xml页面是 <entry> <id>xxxxx</id> <title>xxx xxxx xxxx</title> <content>xxxxxxxxxxx</content> <media:group> <media:thumbnail url="http://tiger.jpg"/>
<entry>
<id>xxxxx</id>
<title>xxx xxxx xxxx</title>
<content>xxxxxxxxxxx</content>
<media:group>
<media:thumbnail url="http://tiger.jpg"/>
</media:group>
</entry>
我可以检索id、标题和内容值并在表视图中显示。如何检索老虎图像URL并在表视图中显示。请帮助我。谢谢
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"media:thumbnail"])
imageUrl=[attributeDict objectForKey:@"url"];
}
由于此方法中已经有if语句,因此对于此语句,请使用else if我应该声明ImageUrl的数据类型“parse did end element”和“found characters”方法中应该给出的内容ImageUrl应该是字符串,也可以用于获取属性值,您不需要在其他方法中指定它。它在何处检查元素解析器将逐个连续检查标记,无论它们是子节点还是父节点,但将其视为字符串。属性值将以属性名称作为键存储在attributeDict中。由于属性在标记中,因此它们是在didStartElement:method中获得的。但标记的值(此处为xxxxx)是在foundCharacters:method处获得的。
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"media:thumbnail"])
imageUrl=[attributeDict objectForKey:@"url"];
}