2011-01-20 1 views
0

나는이 나는 문서의 XSD에서 생성 된 클래스에 직렬화하기 위해 노력하고있어 XML 문서,ASP.NET XML은 어떤 초기화 된 변수 C# 클래스에 직렬화하지 않습니다 제대로

<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; 

이 모든

작동 deserilization가 비어 있고 임의의 값을 반영하지 않습니다 후 반환하지만 개체 deserialize되고있는 xml 문자열에서 발견되었습니다. 아무도 여기서 무엇이 잘못되었는지 압니까? 어떤 도움을 주셔서 감사합니다!

+0

모든 * other * 요소의 네임 스페이스는 무엇입니까? –

+0

또한 클래스 정의 중 일부를 표시하십시오. 나는 그것을 볼 수 없다면 그것이 효과가 있는지 알 방법이 없다. –

+0

초기 질문 이후에 xsd에서 생성 된 C# 클래스가 더 추가되었습니다. 클래스에 몇 가지 문제점을 발견하고 xsd를 수정하여 다시 생성했습니다. 나는 간결함을 위해 콜렉션 클래스를 아직두고있다. 코드는 아직 실행 중이지만 비 직렬화 후에는 빈 모델이됩니다. – Boog

답변

0

나는 아직도 이런 일이 이유를 잘 모르겠지만, 그것은 내 XSD에 스키마 네임 스페이스를 변경하여 지금의 문제를 해결했습니다 모양에 C#을 클래스의 원인

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

,

[XmlRoot(ElementName="DataRequest",Namespace=Declarations.SchemaVersion,IsNullable=false),Serializable] 

지금 그들이 가지고, 그들은 속성을 가지고 전에 반면 빈 공간으로 생성

[XmlRoot(ElementName="DataRequest",IsNullable=false),Serializable] 

내가 대답 할 수있는 사람이 아직도 가지고있는 질문은 왜 XmlSerializer가 내 개체의 가치없는 인스턴스를 반환하는 대신 오류를 보내지 않았는가입니다.