How to work with names.xsd spaces that contain the same elements / classes?

I have a little problem understanding how I should work with xml files, so hopefully you guys can point me in the right direction ... I hope I can explain my problem clearly enough :)

I have a lot of .xsd files, all of which are linked from top to bottom. So I have 10.xsd with namespace A and 10.xsd with namespace B. Let's say two namespaces each represent their own car. This means that they have both the same elements such as an engine, a wheel, etc. I argued that I can use xsd.exe and then just serialize the XML files in my C # code. But when I converted the .xsd files to two .cs files (one for each namespace / car), they share a lot of the same classes. This creates a problem when I want to add two .cs files to my project. Can't have two classes with the same name ... How can I solve this? Am I using the wrong tools or am I completely misunderstanding what I should be doing? :)

Cs file start:

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

      

}

+3


source to share


2 answers


The best way might be to feed all the XSD files on xsd.exe at the same time. To illustrate, if you have three XSD files, you just call it:

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

      



If you need to override the namespace, you simply provide an additional xsd.exe parameter:

/namespace:MyCompany.Xsd.Something

      

+5


source


One way to do this is to create classes in different .Net namespaces.
Then you will have two sets of classes, but since they are in separate namespaces, there will be no conflict in your code.

EDIT:



To tell xsd.exe to use your namespace, use the / namespace parameter, for example:

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

      

+1


source







All Articles