我必须在我的项目中的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/