1

I'm using node-soap with a service and everything works but I need to send an array of ints and I find that I can only send the first one because I can't find the correct way to build a JS object to represent this array.

I've been looking at similar questions but I couldn't find the answer to my question.

I need to generate a XML property like the following one:

<ns1:ArrayOfInts>
          <!--Zero or more repetitions:-->
          <arr:int>2904</arr:int>
          <arr:int>3089</arr:int>
          <arr:int>4531</arr:int>
</ns1:ArrayOfInts>

by passing an object that contains the array:

soapObject = {
              somefields,
              "ns1:ArrayOfInts": {
                 Something goes here
              },
             };

Any idea how to create the JS object?

Community
  • 1
  • 1
Mario
  • 21
  • 3
  • maybe you need to pass an array inside the "ns1:ArrayOfInts" like soapObject= { some:"field", ArrayOfInts: [2904,3089,4531] }; – Amin Mohamed Ajani Jan 27 '16 at 10:18
  • I tried that and it's close but it doesn't include the "arr" namespace prefix which is needed later by the WSDL method, i.e.: 29043089 – Mario Jan 27 '16 at 11:24

1 Answers1

1

I had the same problem and used $xml property to add raw XML to the request and attributes to set the arr namespace:

var fields = [2904, 3089, 4531];
soapObject.arrayOfInts = {
    attributes: {
        'xmlns:arr': 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
    },
    $xml: fields.map(function(value) {
        return '<arr:int>' + value + '</arr:int>';
    }).join('')
};

This code will generate the following request:

<ns1:arrayOfInts xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <arr:int>2904</arr:int>
    <arr:int>3089</arr:int>
    <arr:int>4531</arr:int>
</ns1:arrayOfInts>
ischenkodv
  • 4,205
  • 2
  • 26
  • 34