gpt4 book ai didi

c# - 同一张表 'tableName'不能是两个嵌套关系中的子表

转载 作者:数据小太阳 更新时间:2023-10-29 02:45:53 26 4
gpt4 key购买 nike

使用 XSD.EXE我生成了一个 *.cs 文件来序列化 XML。序列化时出现错误

“同一个表‘DefaultFont’不能是两个嵌套关系中的子表。”

为什么我会收到错误消息?我可以在不使用 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>

生成的代码

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

最佳答案

您生成的一些类在 XmlTypeAttribute 中设置了 AnonymousType=true。当我修改它并添加真实的类名时 - 错误消失了。这是完整的工作示例(请注意,我将“MemoPrompt”和“PromptPlugin”类名称添加到 XmlTypeAttribute):

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

关于c# - 同一张表 'tableName'不能是两个嵌套关系中的子表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13363835/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com