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?
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?
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:
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.