title: Object serialization in XML format using Obj-C / iPhone SDK
body: <p>I have an iPhone App that uses a relatively small amount of data.
  I'd like to save the data in the XML format and be able to load this in memory to Objective-C objects. I'd like to use iPhone SDK facilities like <em>NSPropertyListSerialization</em> or <em>writeToFile:atomically:</em> classes and methods.</p>
  
  <p>The <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSPropertyListSerialization_Class/Reference/Reference.html" rel="nofollow noreferrer">NSPropertyListSerialization documentation</a> says that </p>
  
  <blockquote>
    <p>The NSPropertyListSerialization class
    provides methods that convert property
    list objects to and from several
    serialized formats. Property list
    objects include NSData, NSString,
    NSArray, NSDictionary, NSDate, and
    NSNumber objects.</p>
  </blockquote>
  
  <p>Suppose I'd like to save a couple of <em>Person</em> objects (a family) whose attributes are all <em>property-list types</em>. The only-way I managed to save this in XML Format is by doing:</p>
  
  <pre><code>// container for person objects
  NSMutableArray *family = [[NSMutableArray alloc] init];
  
  for (int i = 0; i &lt; numberOfPeople; i++) {      
   // simulate person's attributes
   NSArray *keys = [[NSArray alloc] initWithObjects:
         @"id", 
         @"name",
         @"age",
         Nil];
  
   NSArray *values = [[NSArray alloc] initWithObjects:
           [NSNumber numberWithInt:i],
           @"Edward", 
           [NSNumber numberWithInt:10],
           Nil];
  
   // create a Person (a dictionary)
   NSDictionary *person = [[NSDictionary alloc] initWithObjects:values forKeys:keys];
   [family addObject:person];
   [person release];  
  }
  
  // save the "person" object to the property list
  [family writeToFile:@"&lt;path&gt;/family.plist" atomically:YES];
  [family release];
  </code></pre>
  
  <p>which would generate the <a href="http://www.educoelho.com/files/family.plist" rel="nofollow noreferrer">family.plist</a> file.</p>
  
  <p>Note, however, that my <em>Person</em> object is actually a NSDictionary object (which I don't think subclassing would be a good idea) with attributes as keys. 
  Is there any way to create a Objective-C class like this:</p>
  
  <pre><code>@interface Person : NSObject {
   NSString *_id; 
   NSString *_name;
   NSNumber *_age;
  }
  @end
  </code></pre>
  
  <p>and serialize it to a plist/XML file? (I need to save the object in text format (not binary) so that I can edit such data in a text editor and allow my application to load this at runtime, converting to Objective-C objects normally).</p>
  
  <p>Thanks in advance,
  Eduardo</p>