Skip to content

Commit 92216e2

Browse files
committed
Merge pull request vpulim#522 from Mik13/master
Use correct namespaces for elements which consist of an array.
2 parents d0d730d + 70691c2 commit 92216e2

File tree

2 files changed

+20
-4
lines changed
  • lib
  • test/request-response-samples/addList__complex_extension_namespace_for_arrays

2 files changed

+20
-4
lines changed

lib/wsdl.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,12 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
14241424
var self = this;
14251425
var schema = this.definitions.schemas[xmlns];
14261426

1427+
var parentNamespace = namespace ? namespace.parent : undefined;
1428+
if(parentNamespace) {
1429+
//we got the parentNamespace for our array. setting the namespace-variable back to the current namespace string
1430+
namespace = namespace.current;
1431+
}
1432+
14271433
var soapHeader = !schema;
14281434
var qualified = schema && schema.$elementFormDefault === 'qualified';
14291435
var parts = [];
@@ -1456,10 +1462,12 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
14561462

14571463
if (Array.isArray(obj)) {
14581464
for (var i = 0, item; item = obj[i]; i++) {
1459-
var arrayAttr = self.processAttributes(item);
1460-
parts.push(['<', ns, name, arrayAttr, xmlnsAttrib, '>'].join(''));
1465+
var arrayAttr = self.processAttributes(item),
1466+
correctOuterNamespace = parentNamespace || ns; //using the parent namespace if given
1467+
1468+
parts.push(['<', correctOuterNamespace, name, arrayAttr, xmlnsAttrib, '>'].join(''));
14611469
parts.push(self.objectToXML(item, name, namespace, xmlns, false, null, parameterTypeObject, ancXmlns));
1462-
parts.push(['</', ns, name, '>'].join(''));
1470+
parts.push(['</', correctOuterNamespace, name, '>'].join(''));
14631471
}
14641472
} else if (typeof obj === 'object') {
14651473
for (name in obj) {
@@ -1522,6 +1530,14 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
15221530
}
15231531
}
15241532

1533+
if(Array.isArray(child)) {
1534+
//for arrays, we need to remember the current namespace
1535+
childNamespace = {
1536+
current: childNamespace,
1537+
parent: ns
1538+
};
1539+
}
1540+
15251541
value = self.objectToXML(child, name, childNamespace, childXmlns, false, childXmlnsAttrib, completeChildParameterTypeObject, ancXmlns);
15261542
} else if (obj[self.options.attributesKey] && obj[self.options.attributesKey].xsi_type) { //if parent object has complex type defined and child not found in parent
15271543
var completeChildParamTypeObject = self.findChildParameterObjectFromSchema(obj[self.options.attributesKey].xsi_type.type, obj[self.options.attributesKey].xsi_type.xmlns);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="urn:platform_2013_2.webservices.netsuite.com" xmlns:platformMsgs="urn:messages_2013_2.platform.webservices.netsuite.com" xmlns:platformFaults="urn:faults_2013_2.platform.webservices.netsuite.com"><soap:Body><platformMsgs:addList xmlns:platformMsgs="urn:messages_2013_2.platform.webservices.netsuite.com" xmlns="urn:messages_2013_2.platform.webservices.netsuite.com"><platformCore:record xsi:type="ns1:Contact" xmlns:ns1="urn:relationships_2013_2.lists.webservices.netsuite.com" xmlns:platformCore="urn:core_2013_2.platform.webservices.netsuite.com"><ns1:firstName>First-1400867779067</ns1:firstName><ns1:lastName>Sullivan</ns1:lastName><ns1:phone>800-555-2819</ns1:phone><ns1:subsidiary internalId="1" xsi:type="ns2:RecordRef" xmlns:ns2="urn:core_2013_2.platform.webservices.netsuite.com"></ns1:subsidiary></platformCore:record><platformCore:record xsi:type="ns3:Contact" xmlns:ns3="urn:relationships_2013_2.lists.webservices.netsuite.com" xmlns:platformCore="urn:core_2013_2.platform.webservices.netsuite.com"><ns3:firstName>aLFirst-1400867779067</ns3:firstName><ns3:lastName>Sullivan</ns3:lastName><ns3:phone>800-555-2819</ns3:phone><ns3:subsidiary internalId="1" xsi:type="ns4:RecordRef" xmlns:ns4="urn:core_2013_2.platform.webservices.netsuite.com"></ns3:subsidiary></platformCore:record></platformMsgs:addList></soap:Body></soap:Envelope>
1+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="urn:platform_2013_2.webservices.netsuite.com" xmlns:platformMsgs="urn:messages_2013_2.platform.webservices.netsuite.com" xmlns:platformFaults="urn:faults_2013_2.platform.webservices.netsuite.com"><soap:Body><platformMsgs:addList xmlns:platformMsgs="urn:messages_2013_2.platform.webservices.netsuite.com" xmlns="urn:messages_2013_2.platform.webservices.netsuite.com"><platformMsgs:record xsi:type="ns1:Contact" xmlns:ns1="urn:relationships_2013_2.lists.webservices.netsuite.com" xmlns:platformCore="urn:core_2013_2.platform.webservices.netsuite.com"><ns1:firstName>First-1400867779067</ns1:firstName><ns1:lastName>Sullivan</ns1:lastName><ns1:phone>800-555-2819</ns1:phone><ns1:subsidiary internalId="1" xsi:type="ns2:RecordRef" xmlns:ns2="urn:core_2013_2.platform.webservices.netsuite.com"></ns1:subsidiary></platformMsgs:record><platformMsgs:record xsi:type="ns3:Contact" xmlns:ns3="urn:relationships_2013_2.lists.webservices.netsuite.com" xmlns:platformCore="urn:core_2013_2.platform.webservices.netsuite.com"><ns3:firstName>aLFirst-1400867779067</ns3:firstName><ns3:lastName>Sullivan</ns3:lastName><ns3:phone>800-555-2819</ns3:phone><ns3:subsidiary internalId="1" xsi:type="ns4:RecordRef" xmlns:ns4="urn:core_2013_2.platform.webservices.netsuite.com"></ns3:subsidiary></platformMsgs:record></platformMsgs:addList></soap:Body></soap:Envelope>

0 commit comments

Comments
 (0)