简体   繁体   English

如何将本地保存的xml文件保存到.plist文件中

[英]How to save locally saved xml file into .plist file

I need to write and update XML file based on nodes.我需要基于节点编写和更新 XML 文件。

For that I found that I need to convert local XML file into plist file.为此,我发现我需要将本地 XML 文件转换为 plist 文件。

Then I can able to update, read and write into plist file as we need.然后我可以根据需要更新、读取和写入 plist 文件。

But I didn't found any sample code regarding this.但我没有找到任何关于此的示例代码。

Can anyone please post some code regarding how can I save local xml file into plist file ?谁能发布一些关于如何将本地 xml 文件保存到 plist 文件中的代码?

How can I read, write and update that locally saved plist file ?如何读取、写入和更新本地保存的 plist 文件

You first need to parse the XML file into NSDictionary and NSArray and NSString objects and then you can save it with -[NSDictionary/NSArray writeToURL:atomically:] .您首先需要将 XML 文件解析为NSDictionaryNSArrayNSString对象,然后可以使用-[NSDictionary/NSArray writeToURL:atomically:]保存它。

There are various tutorials available on how to parse XML.有很多关于如何解析 XML 的教程。 I recommend TBXML as it's extremely fast.我推荐TBXML ,因为它非常快。

You would parse the XML file and put the data into an NSDictionary with keys like this:您将解析 XML 文件并将数据放入具有如下键的NSDictionary

  • Name: NSString with the name of the element名称:带有元素名称的NSString
  • Attributes: NSDictionary of attributes属性:属性的NSDictionary
  • Text: NSString containing the text in the element Text:包含元素中文本的NSString
  • Sub-elements: NSArray of sub-elements (array of dictionaries like this one)子元素:子元素的NSArray (像这样的字典数组)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM