borna borna - 3 years ago 163
iOS Question

Parsing local xml file with iOS swift

I was looking at this example for parsing xml using swift

as you can see in the example, the xml file is located somewhere in the web

var url:String=""
var urlToSend: NSURL = NSURL(string: url)

I want to do the same, but instead I want to have the xml file locally as part of my single view project.
Where in the project I should place the xml file?

How can I access it from the file?

Answer Source

Just drag the file anywhere in your XCode project. Then you just access it like

let xmlPath = NSBundle.mainBundle().pathForResource(fileName, ofType: "xml")
let xmlData = NSData(contentsOfFile: xmlPath)

Now you can parse your xmlData.I use AEXML for that purpose, but you can use any other libraries.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download