如何读取和解析 .xml 文件
我需要简单地读取 .xml 文件;像这样:
<exchanges>
<exchange>
<timestamp>2010-08-19 17:15:56</timestamp>
<userid>Elijah-Woods-MacBook-Pro.local</userid>
<clientname>elijah</clientname>
<botid>Jarvis</botid>
<input>firsthello</input>
<response>Hello, sir. How may I help you?</response>
</exchange>
</exchanges>
然后,解析“response”标签之间的所有内容。
以利亚
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TouchXML 也是 iPhone 上一个非常好的 XML 库。它也被证明是解析最快的之一。
这是一个示例项目: http://dblog.com.au/general/iphone-sdk-tutorial-building-an-advanced-rss-reader-using-touchxml-part-1/
网上还有很多如果你擅长“touchxml iphone 教程”
TouchXML is also a very good library for XML on iPhone. It is been proved to be one of the fastest for parsing too.
Here is an examples project: http://dblog.com.au/general/iphone-sdk-tutorial-building-an-advanced-rss-reader-using-touchxml-part-1/
There are many more online if you good "touchxml iphone tutorial" though
在 Cocoa 中解析 XML 有两种选择:
事件驱动的解析占用的内存较少,但由于您没有构建整个 XML 树,因此无法使用 XPath 或 XQuery 来获取有关文档的信息。基于树的结构通常使用更多的内存(因为整个 XML 文档被转换为对象形式并存储在内存中),但它提供了更强大的机制来从树中获取数据。
You have two choices for parsing XML in Cocoa:
Event-driven parsing is less memory-intensive, but since you don't build a whole XML tree, you can't use XPath or XQuery to get information about the document. Tree-based generally uses more memory (since the entire XML document is converted into a object form and stored in memory), but it offers more powerful mechanisms for getting data out of the tree.
基本思想,代码不完整..基于GDataXML
http://code.google.com/p/gdata-objectivec-client/source/browse/trunk/Source/XMLSupport/
还可查看对多个解析器的分析
http://www.raywenderlich.com/553 /如何为您的 iPhone 项目选择最佳 xml 解析器
Basic idea, the code is not complete.. based on GDataXML
http://code.google.com/p/gdata-objectivec-client/source/browse/trunk/Source/XMLSupport/
also see this analysis of multiple parsers
http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project