2012-11-13 6 views
3

XSD.EXE 사용 XML을 직렬화하기 위해 * .cs 파일을 생성했습니다. 내가 오류를 얻을 직렬화하는 경우동일한 테이블 'tableName'은 두 개의 중첩 된 관계에있는 하위 테이블이 될 수 없습니다.

"The same table 'DefaultFont' cannot be the child table in two nested relations."

는 이유는 오류가 발생합니까? XSLT 변환을 사용하지 않고 오류를 해결할 수 있습니까?

코드

 StreamReader fs = new StreamReader(@"C:\path\DocumentSample.xml"); 
     XmlSerializer serializer = new XmlSerializer(typeof(PhysDocDocument)); 
     var result = serializer.Deserialize(fs) as PhysDocDocument;//exception thrown here 

샘플 XML

<PhysDocDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <PhysDocNode HeaderVisible="true" Display="Summary" IsCollapsed="false" CopyForwardEnabled="true" IsHidden="false" Borders="false"> 
     <LinkedPluginId>00000000-0000-0000-0000-000000000000</LinkedPluginId> 
     <Plugin xsi:type="PromptPlugin" ID="2446441e-6eb2-49ef-b8e3-28f638755b75"> 
      <CopyForwardChecked>true</CopyForwardChecked> 
      <PromptBase xsi:type="MemoPrompt"> 
       <Label>Comment</Label> 
       <DocumentValue> 
        <Paragraphs /> 
        <DefaultFont FontFamily="Arial" SizeInPoints="10" Style="Regular" /> 
       </DocumentValue> 
       <ShowLabel>false</ShowLabel> 
       <RenderHeader>false</RenderHeader> 
      </PromptBase> 
     </Plugin> 
    </PhysDocNode> 
</PhysDocDocument> 

생성 된 코드 생성 된 클래스의 일부가 XmlTypeAttribute에서 AnonymousType가 = true로 설정해야

//------------------------------------------------------------------------------ 
// <auto-generated> 
//  This code was generated by a tool. 
//  Runtime Version:4.0.30319.17929 
// 
//  Changes to this file may cause incorrect behavior and will be lost if 
//  the code is regenerated. 
// </auto-generated> 
//------------------------------------------------------------------------------ 

using System.Xml.Serialization; 

// 
// This source code was auto-generated by xsd, Version=4.0.30319.1. 
// 


/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)] 
public partial class PhysDocDocument 
{ 

    private PhysDocDocumentPhysDocNode[] itemsField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("PhysDocNode", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public PhysDocDocumentPhysDocNode[] Items 
    { 
     get 
     { 
      return this.itemsField; 
     } 
     set 
     { 
      this.itemsField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
public partial class PhysDocDocumentPhysDocNode 
{ 

    private string linkedPluginIdField; 

    private PhysDocDocumentPhysDocNodePlugin[] pluginField; 

    private string headerVisibleField; 

    private string displayField; 

    private string isCollapsedField; 

    private string copyForwardEnabledField; 

    private string isHiddenField; 

    private string bordersField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string LinkedPluginId 
    { 
     get 
     { 
      return this.linkedPluginIdField; 
     } 
     set 
     { 
      this.linkedPluginIdField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("Plugin", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public PhysDocDocumentPhysDocNodePlugin[] Plugin 
    { 
     get 
     { 
      return this.pluginField; 
     } 
     set 
     { 
      this.pluginField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string HeaderVisible 
    { 
     get 
     { 
      return this.headerVisibleField; 
     } 
     set 
     { 
      this.headerVisibleField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string Display 
    { 
     get 
     { 
      return this.displayField; 
     } 
     set 
     { 
      this.displayField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string IsCollapsed 
    { 
     get 
     { 
      return this.isCollapsedField; 
     } 
     set 
     { 
      this.isCollapsedField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string CopyForwardEnabled 
    { 
     get 
     { 
      return this.copyForwardEnabledField; 
     } 
     set 
     { 
      this.copyForwardEnabledField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string IsHidden 
    { 
     get 
     { 
      return this.isHiddenField; 
     } 
     set 
     { 
      this.isHiddenField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string Borders 
    { 
     get 
     { 
      return this.bordersField; 
     } 
     set 
     { 
      this.bordersField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
public partial class PhysDocDocumentPhysDocNodePlugin 
{ 

    private string copyForwardCheckedField; 

    private PhysDocDocumentPhysDocNodePluginPromptBase[] promptBaseField; 

    private string idField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string CopyForwardChecked 
    { 
     get 
     { 
      return this.copyForwardCheckedField; 
     } 
     set 
     { 
      this.copyForwardCheckedField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("PromptBase", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public PhysDocDocumentPhysDocNodePluginPromptBase[] PromptBase 
    { 
     get 
     { 
      return this.promptBaseField; 
     } 
     set 
     { 
      this.promptBaseField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string ID 
    { 
     get 
     { 
      return this.idField; 
     } 
     set 
     { 
      this.idField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
public partial class PhysDocDocumentPhysDocNodePluginPromptBase 
{ 

    private string labelField; 

    private string showLabelField; 

    private string renderHeaderField; 

    private PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValue[] documentValueField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string Label 
    { 
     get 
     { 
      return this.labelField; 
     } 
     set 
     { 
      this.labelField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string ShowLabel 
    { 
     get 
     { 
      return this.showLabelField; 
     } 
     set 
     { 
      this.showLabelField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string RenderHeader 
    { 
     get 
     { 
      return this.renderHeaderField; 
     } 
     set 
     { 
      this.renderHeaderField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("DocumentValue", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValue[] DocumentValue 
    { 
     get 
     { 
      return this.documentValueField; 
     } 
     set 
     { 
      this.documentValueField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
public partial class PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValue 
{ 

    private string paragraphsField; 

    private PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValueDefaultFont[] defaultFontField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string Paragraphs 
    { 
     get 
     { 
      return this.paragraphsField; 
     } 
     set 
     { 
      this.paragraphsField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("DefaultFont", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValueDefaultFont[] DefaultFont 
    { 
     get 
     { 
      return this.defaultFontField; 
     } 
     set 
     { 
      this.defaultFontField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
public partial class PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValueDefaultFont 
{ 

    private string fontFamilyField; 

    private string sizeInPointsField; 

    private string styleField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string FontFamily 
    { 
     get 
     { 
      return this.fontFamilyField; 
     } 
     set 
     { 
      this.fontFamilyField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string SizeInPoints 
    { 
     get 
     { 
      return this.sizeInPointsField; 
     } 
     set 
     { 
      this.sizeInPointsField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string Style 
    { 
     get 
     { 
      return this.styleField; 
     } 
     set 
     { 
      this.styleField = value; 
     } 
    } 
} 

답변

0

를 직렬화합니다. 이것을 수정하고 실제 클래스 이름을 추가하면 오류가 사라집니다. 다음은 전체 작동 예제입니다 (XmlTypeAttribute에 'MemoPrompt'및 'PromptPlugin'클래스 이름 추가).

using System.Xml.Serialization; 
using System.IO; 
using System; 

class App 
{ 
    static void Main() 
    { 
    StreamReader fs = new StreamReader(@"sample.xml"); 
    XmlSerializer serializer = new XmlSerializer(typeof(PhysDocDocument)); 
    var result = serializer.Deserialize(fs) as PhysDocDocument; 
    Console.WriteLine(result); 
    } 
} 


/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)] 
public partial class PhysDocDocument 
{ 

    private PhysDocDocumentPhysDocNode[] itemsField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("PhysDocNode", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public PhysDocDocumentPhysDocNode[] Items 
    { 
     get 
     { 
      return this.itemsField; 
     } 
     set 
     { 
      this.itemsField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
public partial class PhysDocDocumentPhysDocNode 
{ 

    private string linkedPluginIdField; 

    private PhysDocDocumentPhysDocNodePlugin[] pluginField; 

    private string headerVisibleField; 

    private string displayField; 

    private string isCollapsedField; 

    private string copyForwardEnabledField; 

    private string isHiddenField; 

    private string bordersField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string LinkedPluginId 
    { 
     get 
     { 
      return this.linkedPluginIdField; 
     } 
     set 
     { 
      this.linkedPluginIdField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("Plugin", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public PhysDocDocumentPhysDocNodePlugin[] Plugin 
    { 
     get 
     { 
      return this.pluginField; 
     } 
     set 
     { 
      this.pluginField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string HeaderVisible 
    { 
     get 
     { 
      return this.headerVisibleField; 
     } 
     set 
     { 
      this.headerVisibleField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string Display 
    { 
     get 
     { 
      return this.displayField; 
     } 
     set 
     { 
      this.displayField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string IsCollapsed 
    { 
     get 
     { 
      return this.isCollapsedField; 
     } 
     set 
     { 
      this.isCollapsedField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string CopyForwardEnabled 
    { 
     get 
     { 
      return this.copyForwardEnabledField; 
     } 
     set 
     { 
      this.copyForwardEnabledField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string IsHidden 
    { 
     get 
     { 
      return this.isHiddenField; 
     } 
     set 
     { 
      this.isHiddenField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string Borders 
    { 
     get 
     { 
      return this.bordersField; 
     } 
     set 
     { 
      this.bordersField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute("PromptPlugin")] 
public partial class PhysDocDocumentPhysDocNodePlugin 
{ 

    private string copyForwardCheckedField; 

    private PhysDocDocumentPhysDocNodePluginPromptBase[] promptBaseField; 

    private string idField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string CopyForwardChecked 
    { 
     get 
     { 
      return this.copyForwardCheckedField; 
     } 
     set 
     { 
      this.copyForwardCheckedField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("PromptBase", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public PhysDocDocumentPhysDocNodePluginPromptBase[] PromptBase 
    { 
     get 
     { 
      return this.promptBaseField; 
     } 
     set 
     { 
      this.promptBaseField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string ID 
    { 
     get 
     { 
      return this.idField; 
     } 
     set 
     { 
      this.idField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute("MemoPrompt")] 
public partial class PhysDocDocumentPhysDocNodePluginPromptBase 
{ 

    private string labelField; 

    private string showLabelField; 

    private string renderHeaderField; 

    private PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValue[] documentValueField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string Label 
    { 
     get 
     { 
      return this.labelField; 
     } 
     set 
     { 
      this.labelField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string ShowLabel 
    { 
     get 
     { 
      return this.showLabelField; 
     } 
     set 
     { 
      this.showLabelField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string RenderHeader 
    { 
     get 
     { 
      return this.renderHeaderField; 
     } 
     set 
     { 
      this.renderHeaderField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("DocumentValue", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValue[] DocumentValue 
    { 
     get 
     { 
      return this.documentValueField; 
     } 
     set 
     { 
      this.documentValueField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
public partial class PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValue 
{ 

    private string paragraphsField; 

    private PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValueDefaultFont[] defaultFontField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string Paragraphs 
    { 
     get 
     { 
      return this.paragraphsField; 
     } 
     set 
     { 
      this.paragraphsField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("DefaultFont", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValueDefaultFont[] DefaultFont 
    { 
     get 
     { 
      return this.defaultFontField; 
     } 
     set 
     { 
      this.defaultFontField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
public partial class PhysDocDocumentPhysDocNodePluginPromptBaseDocumentValueDefaultFont 
{ 

    private string fontFamilyField; 

    private string sizeInPointsField; 

    private string styleField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string FontFamily 
    { 
     get 
     { 
      return this.fontFamilyField; 
     } 
     set 
     { 
      this.fontFamilyField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string SizeInPoints 
    { 
     get 
     { 
      return this.sizeInPointsField; 
     } 
     set 
     { 
      this.sizeInPointsField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string Style 
    { 
     get 
     { 
      return this.styleField; 
     } 
     set 
     { 
      this.styleField = value; 
     } 
    } 
}