I am trying to deserialize an XML element that I received from a SOAP response, but I am getting the "Namespace prefix 'xsd' is not defined" error. What's the possible solution for this?
Here's the sample response XML I'm getting:
<ns0:response xmlns:ns0="http://sample.site.com">
<ns0:additionalData>
<ns0:entry>
<ns0:key xsi:type="xsd:string">Test Key</ns0:key>
<ns0:value xsi:type="xsd:string">1</ns0:value>
</ns0:entry>
<ns0:entry>
<ns0:key xsi:type="xsd:string">Test Code</ns0:key>
<ns0:value xsi:type="xsd:string">1</ns0:value>
</ns0:entry>
</ns0:additionalData>
<ns0:mpiData>
<ns1:authenticationResponse xmlns:ns1="http://sample.site2.com">Y</ns1:authenticationResponse>
</ns0:mpiData>
</ns0:response>
I'm deserializing it this way:
XDocument xDocument = XDocument.Parse(responseText);
var responseElement = xDocument.Descendants().Where(a => a.Name.LocalName == response.ElementName).Select(a => a).Last();
TResponse response = default(TResponse);
Stream memoryStream = new MemoryStream();
responseElement.Save(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
var serializer = new XmlSerializer(typeof(TResponse));
using (XmlReader xmlReader = XmlReader.Create(memoryStream))
{
response = (TResponse)serializer.Deserialize(xmlReader);
}
return response;
CreateReaderon theXElementto get anXmlReaderand get rid of the intermediate messing about with streams? It does appear to be a fragment with undeclared prefixes.xsdprefix is missing, but from the sample it looks like thexsiprefix is missing. It also seems, as @Damien_The_Unbeliever suggests, the actual issue relates to this 'base64' data, but this cannot be reproduced from your sample XML and code.