Reputation: 455
I built an iPhone app that is getting information from a server (this is also a server that I built).
The data from the server is XML
and I use the XML parser to parse the message.
What I want is to add an image to be sent from the server, and I am asking if I can add binary data of such an image to the XML message. For example 10 tags will be text and 1 tag will be binary (the image). So when the XML parser gets to the binary tag, it inserts the data to NSDATA
object and the rest of the tags will be inserted to NSString
.
Does the XML parser of Cocoa
can handle this situation?
If not, what do you think will be the easiest way to do this with one connection to the server so that the data from the server is sent once.
Upvotes: 1
Views: 356
Reputation: 121
You can transfer the image data, encoded using Base64. There is this NSData category by Matt Gallagher that adds Base64 decoding support to NSData (dateFromBase64String). You can find it on his Cocoa with love website.
Mind you that encoding images in Base64 adds about 33% in file size.
Upvotes: 1
Reputation: 2931
To transfer binary data wrapped in XML, encode it using e.g. Base64, which turns your binary data into characters that won't mess up your XML.
Upvotes: 1