加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在Swift中处理XML元素的属性

发布时间:2020-12-14 04:43:51 所属栏目:百科 来源:网络整理
导读:我想通过使用NS XMLParser从这个元素中读取url属性: enclosure url="http://www.marketoloji.com/wp-content/uploads/2015/01/IMG_1649-110x110.jpg" length="7113" type="image/jpg"/ 我在Apple网站上找到了这个资源,但它是针对obj C的,而不是针对Swift的
我想通过使用NS XMLParser从这个元素中读取url属性:

<enclosure url="http://www.marketoloji.com/wp-content/uploads/2015/01/IMG_1649-110x110.jpg" length="7113" type="image/jpg"/>

我在Apple网站上找到了这个资源,但它是针对obj C的,而不是针对Swift的:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/XMLParsing/Articles/HandlingElements.html#//apple_ref/doc/uid/20002265-BCIJFGJI

我知道我应该在didStartElement方法中使用attributeDict字典,但不知道如何.

解决方法

我学会了它,这是它在Swift中的工作方式:

在didStartElement方法中;

if element.isEqualToString("enclosure") {
        var imgLink = attributeDict["url"] as String
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读