I need to write and update XML file based on nodes.
For that开发者_如何转开发 I found that I need to convert local XML file into plist file.
Then I can able to update, read and write into plist file as we need.
But I didn't found any sample code regarding this.
Can anyone please post some code regarding how can I save local xml file into plist file?
How can I read, write and update that locally saved plist file?
You first need to parse the XML file into NSDictionary
and NSArray
and NSString
objects and then you can save it with -[NSDictionary/NSArray writeToURL:atomically:]
.
There are various tutorials available on how to parse XML. I recommend TBXML as it's extremely fast.
You would parse the XML file and put the data into an NSDictionary
with keys like this:
- Name:
NSString
with the name of the element - Attributes:
NSDictionary
of attributes - Text:
NSString
containing the text in the element - Sub-elements:
NSArray
of sub-elements (array of dictionaries like this one)
精彩评论