在 Swift 中处理 XML 元素的属性 [英] Handling an attribute of an XML element in Swift
本文介绍了在 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:
我知道我应该在 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屋!
查看全文