# How to send xml over tcp?

**URL:** <https://discourse.nodered.org/t/how-to-send-xml-over-tcp/24663>\
**Category:** General\
**Created:** [11 April 2020 18:36 UTC](https://discourse.nodered.org/t/how-to-send-xml-over-tcp/24663 "2020-04-11T18:36:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![knoepsche](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knoepsche/32/69450_2.png) [@knoepsche](https://discourse.nodered.org/u/knoepsche)\
**Post date:** [11 April 2020 18:36 UTC](https://discourse.nodered.org/t/how-to-send-xml-over-tcp/24663/1 "2020-04-11T18:36:18Z")

</div>

What is the right way to send xml over tcp?

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

```auto
* 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_ :

```auto
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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [11 April 2020 20:14 UTC](https://discourse.nodered.org/t/how-to-send-xml-over-tcp/24663/2 "2020-04-11T20:14:02Z")

</div>

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

```auto
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).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 June 2020 20:14 UTC](https://discourse.nodered.org/t/how-to-send-xml-over-tcp/24663/3 "2020-06-10T20:14:03Z")

</div>

Closed on 10 June 2020 20:14 UTC

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