Encode XML string to EXI and send it through a websocket
First of all I am using a client-server architecture, android for the client and node.js for the server, they are connected through Socket.io library, so, they are using websockets.
The doubt that I have is that I am generating a XML String with XMLSerializer from Java, I want to encode it to EXI and send it to a server, thus, is it possible doing the encode XML-EXI without using files? directly from string to string? because all examples I see assume that my XML is in a file and I want the output into another file. Another doubt is, can I just send the EXI as string? because I have already established the communication between the client and the server, but they just send strings, I don not if I can sent whole files, in that case, would be any diference on the amount of data sent?
Finally I have solved it, for people with the same problem, the solution is:
String input = methodGivingXMLString(); byte inputBytes = input.getBytes(); ByteArrayInputStream in = new ByteArrayInputStream(inputBytes); transmogrifier.encode(new InputSource(in));
For the input, and for the output:
ByteArrayOutputStream result = new ByteArrayOutputStream(); transmogrifier.setOutputStream(result);
note 1: I am using OpenExi library
note 2: The output stream has to be set before calling the encode() method.