How to save locally saved xml file into .plist file
Asked Answered
C

1

11

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?

Crowfoot answered 8/7, 2011 at 10:13 Comment(6)
[[NSArray arrayWithObject:[NSString stringWithContentsOfURL:myXMLFileURL encoding:NSUTF8StringEncoding error:NULL]] writeToURL:myPlistURL atomically:YES]; :)Equanimity
@WTP Y dont you answer it instead of commenting???Intendant
@WTP i need to convert locally saved xml file,not from urlCrowfoot
@Crowfoot a URL can be local (+[NSURL fileURLWithPath:]), it's even recommended by Apple over a path. @Kingofbliss if you read it you can see it's kind of a joke.Equanimity
people who down vote please add comment.i don't think why u people down voteCrowfoot
@WTP i got it..:) @Mahesh waitng for an answer for you question. +1 for ur commentIntendant
E
2

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)
Equanimity answered 8/7, 2011 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.