zoukankan      html  css  js  c++  java
  • Libxml2中使用xpath解析xml问题

    //hack to remove xmlns => avoid xpath search not works  
    //如果节点xml节点含有xmlns,这个时候用xpath是匹配不出节点内容的,只好删掉了,找这个原因不容易啊 - -|||
    xmlStr = [xmlStr stringByReplacingOccurrencesOfString:@"xmlns" withString:@"noNSxml"];
    NSMutableArray
    * contents = [NSMutableArray array];

    NSError
    * error = nil;
    DDXMLDocument
    * xmlDoc = [[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:&error];

    if (error) {
    NSLog(
    @"%@",[error localizedDescription]);
    return nil;
    }

    NSArray
    * resultNodes = nil;
    resultNodes
    = [xmlDoc nodesForXPath:@"//audio | //text | //image | //img" error:&error];

    if (error) {
    NSLog(
    @"%@",[error localizedDescription]);
    return nil;
    }

    for(DDXMLElement* resultElement in resultNodes)
    {
    NSString
    * name = [resultElement name];
    //audio , text or other media type
    NSString* fileName = [[resultElement attributeForName:@"src"] stringValue];
    // 0.txt
    }
  • 相关阅读:
    使用dfs求解全排列
    并查集
    Best Cow Line
    Saruman's Army
    Fence Repair
    Laking Counting
    淘宝商品定向爬取
    爬取股票信息
    python中的正则表达式的使用

  • 原文地址:https://www.cnblogs.com/pipizhu/p/2006817.html
Copyright © 2011-2022 走看看