How i can make an xml file from NSString object?
In other words, how can I parse XML from an NSString object?
How i can make an xml file from NSString object?
In other words, how can I parse XML from an NSString object?
If this is for the iPhone, you might want to take a look at this question which goes over doing it on the iPhone, using the user defaults method.
For reference, on Mac OS X one could use the writeToFile:atomically:encoding:error:
NSString Method.
EDIT: To parse the XML within an NSString, you can use the NSXMLParser
class. This class does not have a method to initialize it with an NSString
, so you have to use its initWithData:
method like this:
NSData *data = [myString dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
And that will initialize it with the NSString
's data.
Of course, you have to learn how to parse the XML itself using this class. You can take a look at this question for some tips, or you can google around for some tutorials, such as Apple's very own walkthrough. Here is another walkthrough for using the class.
If the xml you're parsing is in plist format, you can use the handy-dandy NSPropertyListSerialization
class methods to parse it into a plist object for you.