2011-08-20 207 views
-2

我能够将XML数据读取到字典中,代码如下。将字典写入plist

NSString *testXMLString = @"<items><item id=\"0001\" type=\"donut\"><name>Cake</name><ppu>0.55</ppu><batters><batter id=\"1001\">Regular</batter><batter id=\"1002\">Chocolate</batter><batter id=\"1003\">Blueberry</batter></batters><topping id=\"5001\">None</topping><topping id=\"5002\">Glazed</topping><topping id=\"5005\">Sugar</topping></item></items>"; 
NSError *parseError = nil; 
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:testXMLString error:&parseError]; 
NSLog(@"%@", xmlDictionary); 

终端输出如下。

items =  { 
     item =   { 
      batters =    { 
       batter =     (
             { 
         id = 1001; 
         text = Regular; 
        }, 
             { 
         id = 1002; 
         text = Chocolate; 
        }, 
             { 
         id = 1003; 
         text = Blueberry; 
        } 
       ); 
      }; 
      id = 0001; 
      name =    { 
       text = Cake; 
      }; 
      ppu =    { 
       text = "0.55"; 
      }; 
      topping =    (
           { 
        id = 5001; 
        text = None; 
       }, 
           { 
        id = 5002; 
        text = Glazed; 
       }, 
           { 
        id = 5005; 
        text = Sugar; 
       } 
      ); 
      type = donut; 
     }; 
    }; } 

如何将该字典保存为plist?

回答

1

您可以使用[mydict writeToFile:@"/hello.plist" atomically:YES] ..................................