Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handling nil attributes in response xml

  • Loading branch information...
commit e35308f6ea5dae991657559f825a1d12bf93c6a7 1 parent f53a589
@grahamrhay grahamrhay authored
View
21 lib/wsdl.js
@@ -1090,6 +1090,7 @@ WSDL.prototype.xmlToObject = function(xml) {
}
};
var stack = [{name: null, object: root, schema: schema}];
+ var xmlns = {};
var refs = {}, id; // {id:{hrefs:[],obj:}, ...}
@@ -1103,6 +1104,7 @@ WSDL.prototype.xmlToObject = function(xml) {
topSchema = top.schema,
elementAttributes = {},
hasNonXmlnsAttribute = false,
+ hasNilAttribute = false,
obj = {};
var originalName = name;
@@ -1155,16 +1157,27 @@ WSDL.prototype.xmlToObject = function(xml) {
//Handle element attributes
for(attributeName in attrs){
- if(/^xmlns:?/.test(attributeName))continue;
+ if(/^xmlns:|^xmlns$/.test(attributeName)){
+ xmlns[splitNSName(attributeName).name] = attrs[attributeName];
+ continue;
+ }
hasNonXmlnsAttribute = true;
elementAttributes[attributeName] = attrs[attributeName];
}
+ for(attributeName in elementAttributes){
+ var res = splitNSName(attributeName);
+ if(res.name === 'nil' && xmlns[res.namespace] === 'http://www.w3.org/2001/XMLSchema-instance'){
+ hasNilAttribute = true;
+ break;
+ }
+ }
+
if(hasNonXmlnsAttribute)obj[self.options.attributesKey] = elementAttributes;
if (topSchema && topSchema[name + '[]'])
name = name + '[]';
- stack.push({name: originalName, object: obj, schema: topSchema && topSchema[name], id: attrs.id});
+ stack.push({name: originalName, object: obj, schema: topSchema && topSchema[name], id: attrs.id, nil: hasNilAttribute});
};
p.onclosetag = function(nsName) {
@@ -1175,6 +1188,10 @@ WSDL.prototype.xmlToObject = function(xml) {
topSchema = top.schema,
name = splitNSName(nsName).name;
+ if(cur.nil === true) {
+ return;
+ }
+
if (topSchema && topSchema[name + '[]']) {
if (!topObject[name])
topObject[name] = [];
View
28 test/request-response-samples/Dummy__should_handle_nil/common.xsd
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:tns="http://www.Dummy.com/Common/Types" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.Dummy.com/Common/Types" elementFormDefault="qualified" attributeFormDefault="unqualified">
+ <xs:complexType name="DummyResult">
+ <xs:sequence>
+ <xs:element name="DummyList" type="tns:DummyList" minOccurs="0"/>
+ </xs:sequence>
+ <xs:attribute name="code" type="xs:string" use="optional"/>
+ </xs:complexType>
+ <xs:complexType name="Dummy">
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="language" type="xs:language" use="optional"/>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ <xs:complexType name="DummyList">
+ <xs:sequence>
+ <xs:element name="DummyElement" type="tns:Dummy" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="DummyFilter">
+ <xs:sequence>
+ <xs:element name="DummyIntFilter" type="xs:string" minOccurs="0"/>
+ <xs:element name="DummyStringFilter" type="xs:string" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
+</xs:schema>
+
View
19 test/request-response-samples/Dummy__should_handle_nil/name.xsd
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:c="http://www.Dummy.com/Common/Types" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.Dummy.com/Name/Types" elementFormDefault="qualified" attributeFormDefault="unqualified">
+ <xs:import namespace="common.xsd" schemaLocation="common.xsd"/>
+ <xs:element name="DummyRequest">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="DummyField1" type="xs:string" minOccurs="0"/>
+ <xs:element name="DummyFilter" type="c:DummyFilter" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="DummyResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="DummyResult" type="c:DummyResult"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
View
6 test/request-response-samples/Dummy__should_handle_nil/request.json
@@ -0,0 +1,6 @@
+{
+ "DummyField1": "Humpty",
+ "DummyFilter": {
+ "DummyFilterString": "Dumpty"
+ }
+}
View
1  test/request-response-samples/Dummy__should_handle_nil/request.xml
@@ -0,0 +1 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.Dummy.com" xmlns:n="http://www.Dummy.com/Name/Types"><soap:Header></soap:Header><soap:Body><n:DummyRequest xmlns:n="http://www.Dummy.com/Name/Types" xmlns="http://www.Dummy.com/Name/Types"><n:DummyField1>Humpty</n:DummyField1><n:DummyFilter><c:DummyFilterString xmlns:c="http://www.Dummy.com/Common/Types">Dumpty</c:DummyFilterString></n:DummyFilter></n:DummyRequest></soap:Body></soap:Envelope>
View
6 test/request-response-samples/Dummy__should_handle_nil/response.json
@@ -0,0 +1,6 @@
+{
+ "DummyResult": {
+ "DummyList": {
+ }
+ }
+}
View
12 test/request-response-samples/Dummy__should_handle_nil/response.xml
@@ -0,0 +1,12 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://www.Dummy.com" xmlns:n="http://www.Dummy.com/Name/Types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <soap:Header></soap:Header>
+ <soap:Body>
+ <n:DummyResponse>
+ <n:DummyResult>
+ <c:DummyList xmlns:c="http://www.Dummy.com/Common/Types">
+ <c:DummyElement xsi:nil="true" />
+ </c:DummyList>
+ </n:DummyResult>
+ </n:DummyResponse>
+ </soap:Body>
+</soap:Envelope>
View
42 test/request-response-samples/Dummy__should_handle_nil/soap.wsdl
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+xmlns:xs="http://www.w3.org/2001/XMLSchema"
+xmlns:tns="http://www.Dummy.com" xmlns:n="http://www.Dummy.com/Name/Types" xmlns:ns="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://www.Dummy.com">
+ <wsdl:types>
+ <xs:schema>
+ <xs:import namespace="http://www.Dummy.com/Common/Types" schemaLocation="common.xsd"/>
+ <xs:import namespace="http://www.Dummy.com/Name/Types" schemaLocation="name.xsd"/>
+ </xs:schema>
+ </wsdl:types>
+ <wsdl:message name="DummyRequest">
+ <wsdl:part name="DummyRequest" element="n:DummyRequest"/>
+ </wsdl:message>
+ <wsdl:message name="DummyResponse">
+ <wsdl:part name="DummyResponse" element="n:DummyResponse"/>
+ </wsdl:message>
+ <wsdl:portType name="DummyPortType">
+ <wsdl:operation name="Dummy">
+ <wsdl:input message="tns:DummyRequest"/>
+ <wsdl:output message="tns:DummyResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="DummyBinding" type="tns:DummyPortType">
+ <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="Dummy">
+ <soap:operation soapAction="http://www.Dummy.com#Dummy" style="document"/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="DummyService">
+ <wsdl:port name="DummyPortType" binding="tns:DummyBinding">
+ <soap:address location="http://www.Dummy.com/"/>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
+
Please sign in to comment.
Something went wrong with that request. Please try again.