代码之家  ›  专栏  ›  技术社区  ›  Ankit Sachan

无法在iPhone的XML分析中提取图像URL

  •  0
  • Ankit Sachan  · 技术社区  · 16 年前

    我对iPhone的开发很陌生, 我正在使用XML解析来解析源的内容

    此源包含此行

    <enclosure url="http://www.abc.com/wp-content/uploads/2010/01/abc.jpg" length="64690" type="image/jpg" />
    

    不,我要提取 http://www.abc.com/wp-content/uploads/2010/01/abc.jpg

    XML结构如下

    <item>
    <title>ABC</title>
    
    <description>asgafgfafdasf</description>
    
    <enclosure url="http://www.abc.com/wp-content/uploads/2010/01/abc.jpg" length="64690" type="image/jpg" />
    
    </item>
    

    我得到了与描述和图块相对应的值

    但无法放下逻辑来解析该图像URL

    有什么专横的人能解释一下吗?

    提前十倍

    1 回复  |  直到 16 年前
        1
  •  2
  •   Vladimir    16 年前

    URL值(以及长度和类型)是元素的 attribute . 如果您使用nsxmlparser,那么在委托的didstarteelement方法中,您可以使用:(您还可能希望在检索数据时检查数据是否有效)

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
        attributes:(NSDictionary *)attributeDict {
    ...
       if ([elementName equalsToString:@"enclosure"]){
          NSString* myUrl = [NSString stringWithString:[attributeDict objectForKey:@"url"]];
       }
    ...
    }