ios - 使用 Swift for mobile 对 xml 文件进行操作
<p><p>我必须在项目中的xml文件中做一些操作
像 -</p> 这样的操作
<blockquote>
<p>Inserting the records</p>
<p>Writing the records</p>
<p>Deleting the records at specific location(with index).</p>
</blockquote>
<p>NSXMLDocument 适用于 Mac 操作系统</p>
<p>谁能在不使用第三方框架的情况下帮助我提供一些示例代码来理解和实现对 Xml 文件的操作。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>对于 iOS,Apple 提供了 <a href="https://developer.apple.com/documentation/foundation/xmlparser" rel="noreferrer noopener nofollow">XMLParser</a>用于 swift 的 api 和用于 Objective C 的 NSXMLParser。您可以查看 <a href="https://www.ioscreator.com/tutorials/parse-xml-ios-tutorial" rel="noreferrer noopener nofollow">this</a>教程供引用。</p>
<p>您可以使用以下代码在 iOS 中读取文件</p>
<pre><code>let bundle = NSBundle.mainBundle()
let path = bundle.pathForResource("data", ofType: "json")
let content = NSString.stringWithContentsOfFile(path) as String
</code></pre>
<p>然后将字符串传递给 XMLParser 并实现其委托(delegate)方法。</p>
<p>希望这会有所帮助。</p></p>
<p style="font-size: 20px;">关于ios - 使用 Swift for mobile 对 xml 文件进行操作,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/55351522/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/55351522/
</a>
</p>
页:
[1]