gpt4 book ai didi

c# - 如何使用包含相同元素/类的 different.xsd 命名空间?

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

我在理解我应该如何处理 xml 文件时遇到了一些困难,所以我希望你们能指导我正确的方向:) 希望我能足够清楚地解释我的问题:)

我有很多 .xsd 文件,它们都是从上到下连接的。所以我有 10 个带有命名空间 A 的 .xsd 和 10 个带有命名空间 B 的 .xsd。假设这两个命名空间代表每辆自己的汽车。这意味着它们都有很多相同的元素,比如发动机、车轮等。我认为我可以使用 xsd.exe,然后在我的 C# 代码中序列化 xml 文件。但是当我将 .xsd 文件转换为两个 .cs 文件(每个命名空间/汽车一个)时,它们共享许多相同的类。当我想将这两个 .cs 文件添加到我的项目时,这会产生问题。不能有两个同名的类(class)......我该如何解决这个问题?我是在使用错误的工具还是完全误解了我应该做什么? :)

.cs 文件的开头:

//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.261
//
// 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(Namespace="http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2006/07/01/")]
[System.Xml.Serialization.XmlRootAttribute("FixedFont", Namespace="http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2006/07/01/", IsNullable=false)]
public partial class SimpleFormattedText {

private object[] itemsField;

private ItemsChoiceType[] itemsElementNameField;

private string[] textField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Bold", typeof(BreakableText))]
[System.Xml.Serialization.XmlElementAttribute("Break", typeof(Break))]
[System.Xml.Serialization.XmlElementAttribute("Center", typeof(BreakableText))]
[System.Xml.Serialization.XmlElementAttribute("Italic", typeof(BreakableText))]
[System.Xml.Serialization.XmlElementAttribute("Right", typeof(BreakableText))]
[System.Xml.Serialization.XmlElementAttribute("Space", typeof(Space))]
[System.Xml.Serialization.XmlElementAttribute("Underline", typeof(BreakableText))]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
public object[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ItemsElementName")]
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemsChoiceType[] ItemsElementName {
get {
return this.itemsElementNameField;
}
set {
this.itemsElementNameField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string[] Text {
get {
return this.textField;
}
set {
this.textField = value;
}
}

最佳答案

最好的方法可能是将所有 XSD 文件同时提供给 xsd.exe。只是为了说明,假设您有三个 XSD 文件,您只需将其命名为:

xsd.exe a.xsd b.xsd c.xsd /c

如果你需要覆盖命名空间,你只需要给xsd.exe提供一个额外的参数:

/namespace:MyCompany.Xsd.Something

关于c# - 如何使用包含相同元素/类的 different.xsd 命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9698255/

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