You mentioned that you're sending data over a socket so you're free to use whatever protocol (even if you event one!) you want. I think I'd do something like this:
Send the following over the socket:
command : 1 byte (command, enum, let '1' signifiy add_task)
header_size : 4 byte (1 int, size of header. Header is a XML snippet of meta data like doc_name)
doc_size : 4 byte (1 int, size of raw document )
header_data : header_size bytes of data, interpret as an xml string
doc_data : doc_size bytes, interpret as your raw data type
Of course there are many higher level protocols that can probably handle this and much more. At least this way you're avoiding weird escape sequences, base64, regex, and other parts that will get you into trouble.