Handling an attribute of an XML element in Swift
Asked Answered
O

1

5

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"/>

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

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

Orellana answered 8/2, 2015 at 18:46 Comment(0)
O
7

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

in didStartElement method;

if element.isEqualToString("enclosure") {
        var imgLink = attributeDict["url"] as String
    }
Orellana answered 10/2, 2015 at 2:13 Comment(1)
this worked for me but I had to remove the isEqualToString and just use a traditional comparison operator so: element == "enclosure"Oshiro

© 2022 - 2024 — McMap. All rights reserved.