在 Swift 中处理 XML 元素的属性 [英] Handling an attribute of an XML element in Swift

查看:44
本文介绍了在 Swift 中处理 XML 元素的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 NSXMLParser 从此元素读取 url 属性:

I want to read the url attribute from this element by using NSXMLParser:

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

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

I found this resource on Apple site but it's for obj C, not for Swift:

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

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

I know that I should work with attributeDict dictionary in didStartElement method but dont know how.

推荐答案

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

I learned it and here is the way it works in Swift:

didStartElement方法中;

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

这篇关于在 Swift 中处理 XML 元素的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆