ios - 使用 Swift for mobile 对 xml 文件的操作

标签 ios swift xml

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

Inserting the records

Writing the records

Deleting the records at specific location(with index).

NSXMLDocument 适用于 Mac 操作系统

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

最佳答案

Apple 为 iOS 提供了一个 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/

相关文章:

iOS 7.0 未找到代码签名身份

swift - 观察 Realm 变化不触发

objective-c - 获取地址簿的子数组

swift - 在 Value 是 Array<SomeProtocol> 的情况下扩展 SignalProducerType

ios - 在所有 View Controller 中创建警报功能 - swift

c# - LINQ XML 查询 : How do I perform query for binding?

xml - 使用xpath函数ends-with()来查找数字

java - 类路径资源 Config.xml 中的 XML 文档无效

iphone - 核心动画的鱼眼效果?

ios - 线程阻塞 Objective C