Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Encode XML string to EXI and send it through a websocket

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 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?

Problem courtesy of: Javi


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();

note 1: I am using OpenExi library

note 2: The output stream has to be set before calling the encode() method.

Solution courtesy of: Javi


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Encode XML string to EXI and send it through a websocket


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription