2012-03-14 32 views
3

我有点麻烦了解我应该如何处理xml文件,所以我希望你们可以指导我在正确的方向:)希望我能解释我的问题清楚足够:)如何使用包含相同元素/类的different.xsd命名空间?

我有很多。所有从上到下连接的xsd文件。所以我有10个.xsd与命名空间A和10个.xsd与命名空间B.让我们说,这两个命名空间代表每个自己的汽车。这意味着他们都分享很多相同的元素,如引擎,车轮等.. 我想我可以利用xsd.exe,然后在我的C#代码中将它们序列化为xml文件。但是,当我将.xsd文件转换为两个.cs文件(每个名称空间/汽车一个文件)时,它们共享很多相同的类。当我想将两个.cs文件添加到我的项目时,这会造成问题。不能有两个同名的班级... 我该如何解决这个问题?我是否使用了错误的工具,或者我完全误解了我应该做的事情? :)

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

}

回答

5

,最好的办法可能被证明是所有XSD文件喂XSD。 exe同时运行。只是为了说明,假设你有三个XSD文件,你只需要调用它:

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

如果你需要重写的命名空间,你只需要提供一个额外的参数XSD.EXE:

/namespace:MyCompany.Xsd.Something 
1

一种方式做,这是产生在不同的.NET命名空间中的类。
然后,您将有两组类,但由于它们位于不同的名称空间中,所以在代码中不会有冲突。

编辑:

要指示XSD.EXE使用您的命名空间,使用/命名空间参数,如:

xsd.exe myxsd.xsd /namespace:MyNamespace /classes 
+0

如何? ly上生成的.cs文件包含部分类。我没有看到任何可以更改的名称空间定义。 – Christian 2012-03-14 09:40:22

+0

@ChristianThoressonDahl,看到编辑的答案 – GTG 2012-03-14 12:00:26

相关问题