0

How i can make an xml file from NSString object?

In other words, how can I parse XML from an NSString object?

Jorge Israel Peña
  • 36,800
  • 16
  • 93
  • 123
itsaboutcode
  • 24,525
  • 45
  • 110
  • 156

2 Answers2

1

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.

Community
  • 1
  • 1
Jorge Israel Peña
  • 36,800
  • 16
  • 93
  • 123
0

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.

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498