diff --git a/lib/wsdl.js b/lib/wsdl.js
index 00c0d1e37..e71f46cf6 100644
--- a/lib/wsdl.js
+++ b/lib/wsdl.js
@@ -1292,9 +1292,20 @@ WSDL.prototype.xmlToObject = function(xml) {
if(hasNonXmlnsAttribute)obj[self.options.attributesKey] = elementAttributes;
+ // Pick up the schema for the type specified in element's xsi:type attribute.
+ var xsiTypeSchema;
+ var xsiType = elementAttributes['xsi:type'];
+ if (xsiType) {
+ var type = splitNSName(xsiType);
+ var typeDef = self.findParameterObject(xmlns[type.namespace], type.name);
+ if (typeDef) {
+ xsiTypeSchema = typeDef.description(self.definitions);
+ }
+ }
+
if (topSchema && topSchema[name + '[]'])
name = name + '[]';
- stack.push({name: originalName, object: obj, schema: topSchema && topSchema[name], id: attrs.id, nil: hasNilAttribute});
+ stack.push({name: originalName, object: obj, schema: (xsiTypeSchema || (topSchema && topSchema[name])), id: attrs.id, nil: hasNilAttribute});
};
p.onclosetag = function(nsName) {
diff --git a/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/request.json b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/request.json
new file mode 100644
index 000000000..be09765bc
--- /dev/null
+++ b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/request.json
@@ -0,0 +1,4 @@
+{
+ "metadataType": "CustomObject",
+ "fullNames": "Opportunity"
+}
diff --git a/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/request.xml b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/request.xml
new file mode 100644
index 000000000..be2906b27
--- /dev/null
+++ b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/request.xml
@@ -0,0 +1 @@
+CustomObjectOpportunity
\ No newline at end of file
diff --git a/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/response.json b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/response.json
new file mode 100644
index 000000000..d68c601b6
--- /dev/null
+++ b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/response.json
@@ -0,0 +1,24 @@
+{
+ "result": {
+ "records": [
+ {
+ "attributes": {
+ "xsi:type": "CustomObject"
+ },
+ "fullName": "Opportunity",
+ "businessProcesses": [
+ {
+ "fullName": "Some Process",
+ "isActive": true
+ },
+ {
+ "fullName": "Another Process",
+ "isActive": false
+ }
+ ],
+ "enableFeeds": false,
+ "enableHistory": true
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/response.xml b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/response.xml
new file mode 100644
index 000000000..de7dcb902
--- /dev/null
+++ b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/response.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+ Opportunity
+
+ Some Process
+ true
+
+
+ Another Process
+ false
+
+ false
+ true
+
+
+
+
+
diff --git a/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/soap.wsdl b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/soap.wsdl
new file mode 100644
index 000000000..3d9e07588
--- /dev/null
+++ b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/soap.wsdl
@@ -0,0 +1,129 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Reads metadata entries synchronously.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Manage your Salesforce.com metadata
+
+
+
+
+