NSPropertyListSerialization
has a handy method that does it for you, reading from an NSData
instance:
NSString *source = ... // The XML string
NSData* plistData = [source dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSMutableDictionary* plist = [NSPropertyListSerialization propertyListWithData:plistData
options: NSPropertyListImmutable
format:NULL
error:&error];
As pointed out by @Adam in the comments, the dictionary returned by this method is always mutable. The options
parameter serves to determine if the containers (arrays, dictionaries) held within the plist are also mutable or (the default) immutable.
If you want containers in the property list to also be mutable, you can use NSPropertyListMutableContainers
- or NSPropertyListMutableContainersAndLeaves
, if you need even the leaves to be mutable.