在Swift中处理XML元素的属性

joh*_*fey 5 nsxmlparser swift

我想url通过使用NSXMLParser从这个元素中读取属性:

<enclosure url="http://www.marketoloji.com/wp-content/uploads/2015/01/IMG_1649-110x110.jpg" length="7113" type="image/jpg"/>
Run Code Online (Sandbox Code Playgroud)

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

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

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

joh*_*fey 7

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

didStartElement方法;

if element.isEqualToString("enclosure") {
        var imgLink = attributeDict["url"] as String
    }
Run Code Online (Sandbox Code Playgroud)