Is converting an XML to NSString from NSData, then manipulate string and convert it back to NSData is safe?
I heard it is always safer to work with XML Parsing libraries. Can anyone explain why? and at which points I should be careful if I will use that method? is that a possible encoding problem?
Conversion between NSData and NSString is safe as long as you do the conversion with the original encoding.
Parsing XML as string will onnly work with naive documents. If your XML structure doesn’t change, if the elements you search for are unique, if the contents are only characters, if there are no CDATA sections in the middle, if there are no namespaces, you are safe. Otherwise your code will get easily confused trying to digest the XML. It’s going to be more solid if both the creator and the client of the document abide by the rules set by the XML standard.
If behind all this you are worrying about complexity, it’s easy to operate on XML using XPath. If you worry about speed, maybe you could switch to a faster format like JSON if you are in control of XML generation.