NSXMLDocumentTidyXML and preserving whitespace

305 Views Asked by At

I'm using NSXMLDocument to parse some XML. It's XML that comes in from a web service, and it's often malformed so I need to pass NSXMLDocumentTidyXML to be able to parse it.

However, I'd like to preserve line breaks in text, which NSXMLDocumentTidyXML strips out.

I know from the documentation that the xmlns:space="preserve" attribute will tell the XML tidier to preserve whitespace. However, since I need that to be in the XML before I begin parsing, and it's only after parsing that I can add attributes to nodes, I'm not sure what to do.

Any suggestions? The only thing I can think of at the moment is manually searching through the string for the root tag, applying the attribute by just inserting it into the input string, then parsing that. That seems pretty fragile to me…

0

There are 0 best solutions below