iOS - XML 漂亮打印
我在 iOS 应用程序中使用 GDataXML,想要一种简单的方法来格式化和打印 XML 字符串 - “漂亮的打印”
有谁知道 Objective C 中的算法,或者可以翻译的另一种语言中的算法吗?
I am using GDataXML in my iOS application and want a simple way to format and print an XML string - "pretty print"
Does anyone know of an algorithm in Objective C, or one that works in another language I can translate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以直接修改 GDataXMLNode 的源代码:
替代方案:
由于我不想直接修改库(出于维护原因),因此我编写了该类别以从外部扩展该类:
GDataXMLNode+PrettyFormatter.h:
GDataXMLNode+PrettyFormatter。米:
You can modify the source code of GDataXMLNode direcly:
Alternative:
As I didn't want to modify the library directly (for maintenance reasons), I wrote that category to extend the class from outside:
GDataXMLNode+PrettyFormatter.h:
GDataXMLNode+PrettyFormatter.m:
我已经使用 HTML Tidy (http://tidy.sourceforge.net/) 来完成类似的事情。它是一个 C 库,因此只要您熟悉 C,就可以相当轻松地链接到 Objective C 运行时并从中调用。C++ API 可以从 Objective C++ 调用,因此如果您熟悉 C++,可能会更容易使用目标C++。
我没有使用过 C 或 C++ 绑定;我通过 Ruby 或 Python 完成了它,但它们都是相同的库。它将直接读取 XML(以及可能不干净的 HTML),并且具有简单且漂亮的打印选项。
I've used HTML Tidy (http://tidy.sourceforge.net/) for things like this. It's a C library so can be linked in to and called from an Objective C runtime fairly easily as long as you're comfortable with C. The C++ API is callable from Objective C++ so that might be easier to use if you're comfortable with Objective C++.
I've not used the C or C++ bindings; I did it via Ruby or Python but it's all the same lib. It will read straight XML (as well as potentially dirty HTML) and it has both simple and pretty print options.