0

plistからxmlファイルを変換することは可能ですか、これを変換する方法は?

4

5 に答える 5

2

plistはXML形式のファイルです。次の方法を使用して、plistから辞書にデータを保存できます:-)次に、適切なキー値を使用して値を取得できます!!

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"example.plist"];

NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSString *errorDesc = nil;
NSPropertyListFormat format; 

NSMutableDictionary *tempDict = (NSMutableDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];

//保存したい場合

[tempDict writeToFile:plistPath atomically:YES]
于 2012-07-18T12:54:15.397 に答える
1

まず、次のようにplistファイルをNSDictionaryにロードする必要があります。

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"plist"];;
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:filePath]; //or use dictionaryWithContentsOfURL to get from the web

次に、それをNSDataに変換します

NSData *xmlData = [NSPropertyListSerialization dataFromPropertyList:dictionary format:NSPropertyListXMLFormat_v1_0   errorDescription:nil];
NSString *xmlString = [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding];
于 2012-07-18T12:51:55.617 に答える
1

新しいファイルを追加する(plist)

ソースコード形式で開きます

xmlコードをコピーして貼り付けますコードが正しければ機能します

于 2012-07-18T12:53:37.257 に答える
0

実際には、NSXMLParserに基づいて単純なパーサークラスを作成し、NSXMLParserDelegateに存在するメソッドを使用してデータをウォークし、辞書を返しました。

次に、この辞書をファイルとして保存できます。これはpListになります。

これにより、直接XML-> pListデータ変換が行われ、pListはXMLの正確な表現になります。

Xcodeがこのような一般的なニーズのように思われるため、サンプルファイルとしてこの正確なものを持っていない理由はわかりません。

NSPropertyListSerialization propertyListFromData:plistXMLがそれらすべてを置き換える場合は、コードをもう一度見ていきます。

于 2012-11-02T22:41:49.873 に答える
0

はい、そうです。

xcodeでplistファイルを開きます。plistファイルの複製を作成します。これで、プロンプトウィンドウが表示されます。[フォーマット]ドロップダウンから[プロパティリストXML ]を選択します。拡張子として.xmlを追加します。

楽しんでください:-D

于 2015-02-04T12:11:52.387 に答える