i'm new swift programming.
i using below xml parsing codes display rss feeds. actually, code works want. can not solve problem.
i callback "description","title" , "pubdate" tags xml url. text between "description" tags of rss url use, displays details of news. that's want. but, in different rss url(shared below), there summary information in "description" tags , url of news details in "link" tags. need string value in content of url. can see content, need click url link.
but want display news detail text, automatically, within in textview created without clicking on link. because use string value, process.
i invastigated topic how can couldn't find.
if have solution, share me little example codes?
i hope explained wanted.
the example xml files screenshots below.
current url http://images.apple.com/main/rss/hotnews/hotnews.rss
the news detail in url link http://www.hurriyetdailynews.com/rss.aspx
thanks in advance.
import uikit class parserssfeeds: xmlparser, xmlparserdelegate{ var parser = xmlparser() var news: [dictionary<string, string>]! = array() var elements: [string:string]! = dictionary() var element = string() var header = string() var link = string() var desc = string() var date = string() func parsefromurl(){ news = [] parser = xmlparser(contentsof: nsurl(string: "http://images.apple.com/main/rss/hotnews/hotnews.rss")! url)! parser.delegate = self parser.parse() }
}
extension parserssfeeds { func parser(_ parser: xmlparser, didstartelement elementname: string, namespaceuri: string?, qualifiedname qname: string?, attributes attributedict: [string : string] = [:]) { element = elementname if (elementname) .isequal("item") { elements = dictionary() elements = [:] header = string() header = "" link = string() link = "" desc = string() desc = "" date = string() date = "" } } func parser(_ parser: xmlparser, foundcharacters string: string) { if element .isequal("title"){ header = header + string }else if element .isequal("link"){ link = link + string }else if element .isequal("description"){ desc = desc + string }else if element .isequal("pubdate") { date = date + string } } func parser(_ parser: xmlparser, didendelement elementname: string, namespaceuri: string?, qualifiedname qname: string?) { if (elementname) .isequal("item") { if !header .isequal(nil) { elements["title"] = header } if !link .isequal(nil) { elements["link"] = link } if !desc .isequal(nil) { elements["description"] = desc } if !date .isequal(nil) { elements["pubdate"] = date } news.append(elements) print(news) } } }
Comments
Post a Comment