OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 Swift for mobile 对 xml 文件进行操作 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 22:39
标题: ios - 使用 Swift for mobile 对 xml 文件进行操作

我必须在项目中的xml文件中做一些操作 像 -

这样的操作

Inserting the records

Writing the records

Deleting the records at specific location(with index).

NSXMLDocument 适用于 Mac 操作系统

谁能在不使用第三方框架的情况下帮助我提供一些示例代码来理解和实现对 Xml 文件的操作。



Best Answer-推荐答案


对于 iOS,Apple 提供了 XMLParser用于 swift 的 api 和用于 Objective C 的 NSXMLParser。您可以查看 this教程供引用。

您可以使用以下代码在 iOS 中读取文件

let bundle = NSBundle.mainBundle()
let path = bundle.pathForResource("data", ofType: "json")
let content = NSString.stringWithContentsOfFile(path) as String

然后将字符串传递给 XMLParser 并实现其委托(delegate)方法。

希望这会有所帮助。

关于ios - 使用 Swift for mobile 对 xml 文件进行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55351522/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4