У меня есть XML-документ, который я пытаюсь десериализовать в класс, сгенерированный из xsd документа,
<DataRequest>
<Table Name="B_MH_SS_Buying_Influences" Destination="Influences">
<Row>
<Field Name="ContactID" Destination="ContactID" Type="STANDARD"/>
<Field Name="RoleID" Destination="RoleID" Type="STANDARD"/>
<Field Name="RoleName" Destination="RoleName" Type="STANDARD"/>
</Row>
</Table>
<Field Name="AccountName" Destination="Account" Type="STANDARD"/>
<Field Name="OpportunityName" Destination="Product" Type="STANDARD"/>
<Field Name="OwnerName" Destination="SalesPerson" Type="STANDARD"/>
<Table Name="Contact" Type="STANDARD">
<Row>
<Field Name="ID" Destination="ID" Type="STANDARD"/>
<Field Name="FirstName" Destination="FirstName" Type="STANDARD"/>
<Field Name="LastName" Destination="LastName" Type="STANDARD"/>
<Field Name="Title" Destination="Title" Type="string" Custom="True"/>
</Row>
</Table>
<Table Name="User" Type="STANDARD">
<Row>
<Field Name="ID" Destination="ID" Type="STANDARD"/>
<Field Name="FirstName" Destination="FirstName" Type="STANDARD"/>
<Field Name="LastName" Destination="LastName" Type="STANDARD"/>
</Row>
</Table>
<Table Name="UserData" Type="STANDARD">
<Row>
<Field Name="ReadOnly" Destination="ReadOnly" Type="STANDARD">False</Field>
<Field Name="DateFormat" Destination="DateFormat" Type="STANDARD">mdy</Field>
<Field Name="DateSeparator" Destination="DateSeparator" Type="STANDARD">/</Field>
<Field Name="Language" Destination="Language" Type="STANDARD"/>
<Field Name="CurrencySymbol" Destination="CurrencySymbol" Type="STANDARD"/>
<Field Name="Decimals" Destination="Decimals" Type="STANDARD">.</Field>
<Field Name="Thousands" Destination="Thousands" Type="STANDARD">,</Field>
</Row>
</Table>
</DataRequest>
РЕДАКТИРОВАТЬ: Вот БОЛЬШЕ сгенерированного C #классы, они немного изменились со времени моего первоначального вопроса.
[XmlRoot(ElementName="DataRequest",Namespace=Declarations.SchemaVersion,IsNullable=false),Serializable]
public partial class DataRequest
{
[XmlElement(Type=typeof(Table),ElementName="Table",IsNullable=false,Form=XmlSchemaForm.Qualified,Namespace=Declarations.SchemaVersion)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public TableCollection __TableCollection;
[XmlIgnore]
public TableCollection TableCollection
{
get
{
if (__TableCollection == null) __TableCollection = new TableCollection();
return __TableCollection;
}
set {__TableCollection = value;}
}
[XmlElement(Type=typeof(DataRequestField),ElementName="Field",IsNullable=false,Form=XmlSchemaForm.Qualified,Namespace=Declarations.SchemaVersion)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public DataRequestFieldCollection __FieldCollection;
[XmlIgnore]
public DataRequestFieldCollection FieldCollection
{
get
{
if (__FieldCollection == null) __FieldCollection = new DataRequestFieldCollection();
return __FieldCollection;
}
set {__FieldCollection = value;}
}
[XmlElement(Type=typeof(SamPivotalConnectorWS.Models.Options),ElementName="Options",IsNullable=false,Form=XmlSchemaForm.Qualified,Namespace=Declarations.SchemaVersion)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OptionsCollection __OptionsCollection;
[XmlIgnore]
public OptionsCollection OptionsCollection
{
get
{
if (__OptionsCollection == null) __OptionsCollection = new OptionsCollection();
return __OptionsCollection;
}
set {__OptionsCollection = value;}
}
public DataRequest()
{
}
}
[XmlType(TypeName="Table",Namespace=Declarations.SchemaVersion),Serializable]
public partial class Table
{
[System.Runtime.InteropServices.DispIdAttribute(-4)]
public IEnumerator GetEnumerator()
{
return RowCollection.GetEnumerator();
}
public TableRow Add(TableRow obj)
{
return RowCollection.Add(obj);
}
[XmlIgnore]
public TableRow this[int index]
{
get { return (TableRow) RowCollection[index]; }
}
[XmlIgnore]
public int Count
{
get { return RowCollection.Count; }
}
public void Clear()
{
RowCollection.Clear();
}
public TableRow Remove(int index)
{
TableRow obj = RowCollection[index];
RowCollection.Remove(obj);
return obj;
}
public void Remove(object obj)
{
RowCollection.Remove(obj);
}
[XmlAttribute(AttributeName="Name",DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Name;
[XmlIgnore]
public string Name
{
get { return __Name; }
set { __Name = value; }
}
[XmlAttribute(AttributeName="Destination",DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Destination;
[XmlIgnore]
public string Destination
{
get { return __Destination; }
set { __Destination = value; }
}
[XmlAttribute(AttributeName="Type",DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Type;
[XmlIgnore]
public string Type
{
get { return __Type; }
set { __Type = value; }
}
[XmlElement(Type=typeof(TableRow),ElementName="Row",IsNullable=false,Form=XmlSchemaForm.Qualified,Namespace=Declarations.SchemaVersion)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public TableRowCollection __RowCollection;
[XmlIgnore]
public TableRowCollection RowCollection
{
get
{
if (__RowCollection == null) __RowCollection = new TableRowCollection();
return __RowCollection;
}
set {__RowCollection = value;}
}
public Table()
{
}
}
[XmlType(TypeName="TableRow",Namespace=Declarations.SchemaVersion),Serializable]
public partial class TableRow
{
[System.Runtime.InteropServices.DispIdAttribute(-4)]
public IEnumerator GetEnumerator()
{
return FieldCollection.GetEnumerator();
}
public TableRowField Add(TableRowField obj)
{
return FieldCollection.Add(obj);
}
[XmlIgnore]
public TableRowField this[int index]
{
get { return (TableRowField) FieldCollection[index]; }
}
[XmlIgnore]
public int Count
{
get { return FieldCollection.Count; }
}
public void Clear()
{
FieldCollection.Clear();
}
public TableRowField Remove(int index)
{
TableRowField obj = FieldCollection[index];
FieldCollection.Remove(obj);
return obj;
}
public void Remove(object obj)
{
FieldCollection.Remove(obj);
}
[XmlElement(Type=typeof(TableRowField),ElementName="Field",IsNullable=false,Form=XmlSchemaForm.Qualified,Namespace=Declarations.SchemaVersion)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public TableRowFieldCollection __FieldCollection;
[XmlIgnore]
public TableRowFieldCollection FieldCollection
{
get
{
if (__FieldCollection == null) __FieldCollection = new TableRowFieldCollection();
return __FieldCollection;
}
set {__FieldCollection = value;}
}
public TableRow()
{
}
}
[XmlType(TypeName="TableRowField",Namespace=Declarations.SchemaVersion),Serializable]
public partial class TableRowField
{
[XmlAttribute(AttributeName="Name",DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Name;
[XmlIgnore]
public string Name
{
get { return __Name; }
set { __Name = value; }
}
[XmlAttribute(AttributeName="Destination",DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Destination;
[XmlIgnore]
public string Destination
{
get { return __Destination; }
set { __Destination = value; }
}
[XmlAttribute(AttributeName="Type",DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Type;
[XmlIgnore]
public string Type
{
get { return __Type; }
set { __Type = value; }
}
[XmlText(DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Value;
[XmlIgnore]
public string Value
{
get { return __Value; }
set { __Value = value; }
}
public TableRowField()
{
}
}
Вот код, который я использую для десериализации документа,
XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = "DataRequest";
xRoot.IsNullable = true;
XmlSerializer serializer = new XmlSerializer(typeof(DataRequest), xRoot);
req = serializer.Deserialize(Context.Request.InputStream) as DataRequest;
Все это работает, однакообъект, который возвращается после десерилизации, пуст и не отражает никаких значений, найденных в строке xml, которая десериализуется.Кто-нибудь знает, что здесь не так?Спасибо за любую помощь!