How to send xml over tcp?

What is the right way to send xml over tcp?

The command was explained like this (the xml part is just an example):

* Add\r\n
* <id>\r\n
* <xml><data></data></xml>\r\n\r\n

Before sending the msg to a tcp-out Node I coded in a function Node :

var buf1 = Buffer.from("ADD\r\n4\r\n", 'utf8');
var buf2 = Buffer.from("<xml><data></data></xml>", 'utf8');
var buf3 = Buffer.from("\r\n\r\n", 'utf8');
var arr = [buf1, buf2, buf3];
msg.payload = Buffer.concat(arr);
return msg;

but this way my command didn't work. Perhaps the xml entities should be converted first. I'm not shure about this. Other commands without the xml part work this way.

Well those aren't xml they are just strings so you can just send one string.

var str = "ADD\r\n";
str += "<id>\r\n";
str += "<xml><data></data></xml>\r\n\r\n";
msg.payload = str;
return msg;

Though for most case you only need \n rather than \r\n (unless you are on Windows).

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.