0

I have two XSD files and I need to combine them and generate a .cs file (C# objects).

One XSD is the one we already use (let's call it first.xsd), and we still need the C# objects that are generated from this one. The second.xsd file has changes, such as adding new fields and objects, and also changes in existing objects.

What we need is just a new generated .cs file which still has the objects, properties etc from the first.xsd, and added are the changes from the second.xsd.

I couldn't accomplish this with everything I have done so far. How can I realize this?

<xsd xmlns='http://microsoft.com/dotnet/tools/xsd/'>
    <generateClasses language='CS' namespace='name'>
        <schema>second.xsd</schema>
        <schema>first.xsd</schema>
    </generateClasses>
</xsd>
New Dev
  • 48,427
  • 12
  • 87
  • 129
A. Gh
  • 631
  • 9
  • 24
  • Usually you have a main schema that can have optional user defines. So to add to the main schema all you need to do is the put an "include" referencing the customer user define xsd file. See : https://www.w3schools.com/xml/el_include.asp – jdweng Nov 19 '20 at 11:32
  • I don't know the C# data binding technology so I can't give specific advice, but as a general observation, data binding for XML works very well when the schema is small, simple, and unchanging, and it becomes a nightmare if the schema is large, complex, or changes over time. – Michael Kay Nov 19 '20 at 11:32
  • @MichaelKay And exactly your last point is my case haha. It is immensely large and complex. – A. Gh Nov 19 '20 at 12:11
  • @jdweng The point somehow is that both have a lot of same objects but with some changes. So it will give me errors such as "The simpleType/complexType has already been declard".. and so on. For example, both has an Address object, but in each of the object there are some property differences. I just want to keep older one (first.xsd) and expand it with the new properties of the Address from second.xsd. And this is just one example, but there are many other objects with the same type of changes. – A. Gh Nov 19 '20 at 13:57
  • That is what the include does. You need to add the include to the first xsd so it recognizes the second xsd. – jdweng Nov 19 '20 at 14:03
  • @jdweng I know have the following: But the generated file didn't include the changes from the second.xsd. How do you recommend me to write my .xsd file? – A. Gh Nov 19 '20 at 14:18
  • The main schema has to reference elements in the 2nd schema. They are normally user specified options in the schema. So the main schema would need to be updated with the optional elements for items to be pulled from the 2nd schema. – jdweng Nov 19 '20 at 14:38

0 Answers0