我正在使用需要使用XML文件的iPhone应用程序。我知道如何解析XML,现在我需要获取用户输入的信息,并将其写入xml(相同或新的xml)中,如何实现?
我在google和这里看过,但是部分指南不太清楚,其中一些已弃用。
Tnx为您提供帮助!
创建一个NSMutableString *并将数据附加到XML上。
NSMutableString *xmlstring = [[NSMutableString alloc]init];
[xmlstring appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"];
[xmlstring appendString:@"<RegistrationXml xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n"];
[xmlstring appendString:@"<DataFields>\n"];
[xmlstring appendString:@"<Name>FirstName</Name>\n"];
[xmlstring appendFormat:@"<Value>%@</Value>\n", [self replaceXMLReservedCharactersInString:someString]];
[xmlstring appendString:@"</DataFields>\n"];
[xmlstring appendString:@"</RegistrationXml>\n"];
在哪里
- (NSString *)replaceXMLReservedCharactersInString:(NSString *)string
{
NSString *result;
result = [string stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
result = [result stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
result = [result stringByReplacingOccurrencesOfString:@">" withString:@">"];
return result;
}
然后将其传递...如果要将其写入文件,请搜索NSFileManager。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句