'XML deserialization not binding list of strings
I am trying to deserialize xml into c# classes.
I followed some documentation and generated some c# classes using the commands xsd foo.xml
& xsd foo.xsd /classes
one of the classess generated by commands. The only part that fails to bind is the getMLIstResult
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.8.3928.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public partial class EnvelopeBodyGetMListResponse
{
private string[] getMListResultField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute(IsNullable = false)]
public string[] GetMListResult
{
get
{
return this.getMListResultField;
}
set
{
this.getMListResultField = value;
}
}
}
the xml used to create the xsd
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetMListResponse xmlns="http://tempuri.org/">
<GetMListResult>
<string>string</string>
<string>string</string>
</GetListResult>
</GetListResponse>
</soap:Body>
</soap:Envelope>
xsd used to create the class
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Envelope" targetNamespace="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mstns="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:app1="http://tempuri.org/">
<xs:import namespace="http://tempuri.org/" schemaLocation="Envelope_app1.xsd" />
<xs:element name="Envelope" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msdata:Prefix="soap">
<xs:complexType>
<xs:sequence>
<xs:element name="Body" msdata:Prefix="soap">
<xs:complexType>
<xs:sequence>
<xs:element name="GetMListResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="GetMListResult">
<xs:complexType>
<xs:sequence>
<xs:element name="string" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
a few things to note:
- I am not able to change the way the xml is returned from an api I am trying to work with.
- I also made a few changes to the xsd after it was generated.
- serialization/deserialization works for the most part, but lists/arrays fail to bind
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|