Objective c 如何从文件列表生成NSXMLDocument
我有一个文件列表,如/Test/Demo1/Demo2/Demo3/demo.mp4,希望在Objective-C中生成XML文档。我有一个生成NSMutableDictionary的代码:Objective c 如何从文件列表生成NSXMLDocument,objective-c,cocoa,nsxml,nsxmldocument,nsxmlelement,Objective C,Cocoa,Nsxml,Nsxmldocument,Nsxmlelement,我有一个文件列表,如/Test/Demo1/Demo2/Demo3/demo.mp4,希望在Objective-C中生成XML文档。我有一个生成NSMutableDictionary的代码: -(NSMutableDictionary *)addFile:(NSString *)path toTree:(NSMutableDictionary *)tree { NSMutableDictionary *node = tree; NSArray *components = [path compo
-(NSMutableDictionary *)addFile:(NSString *)path toTree:(NSMutableDictionary *)tree {
NSMutableDictionary *node = tree;
NSArray *components = [path componentsSeparatedByString:@"/"];
for (NSUInteger i = 0; i < [components count] - 1; i++) {
NSString *key = components[i];
if (node[key] == nil) {
node[key] = [NSMutableDictionary dictionary];
}
node = node[key];
}
NSString *name = [components lastObject];
if ([name length] > 0) {
node[name] = [NSMutableDictionary dictionary];
node = node[name];
}
return node;
-(NSMutableDictionary*)添加文件:(NSString*)路径到树:(NSMutableDictionary*)树{
NSMutableDictionary*节点=树;
NSArray*components=[path componentsSeparatedByString:@”/“];
对于(整数i=0;i<[组件计数]-1;i++){
NSString*键=组件[i];
if(节点[键]==nil){
节点[键]=[NSMutableDictionary];
}
节点=节点[键];
}
NSString*name=[components lastObject];
如果([名称长度]>0){
节点[名称]=[NSMutableDictionary];
节点=节点[名称];
}
返回节点;
}
但是我没有好的结果。建议我如何将文件列表转换为NSMutableArray或NSXMLDocument
谢谢中有一些示例。 选中“从现有XML创建文档对象”之后的“创建新XML文档”以及“写出XML文档”,说明如何将其转换为NSData(可以写入文件或转换为NSString) 再来一个 如果要创建形式上一致的标准XML文件,则需要使用此XML API 或者,您可以使用NSMutableString手动构建字符串。使用与您不同的结构工作,但您应该能够获得想法
构建文件和目录树后,可以使用类似的算法遍历它,并在此过程中构建NSXMLDocument或NSMutableString。能否提供所需的输入和输出示例?输入字符串:170d8b9,技术/摄取/演示/PGM__181158; 4.mov和输出:
Technics demo PGM__181158; 4.mov