2

I use command for NetFX 4.5.1 Tools from Microsoft SDK:

xsd schema.xsd /c

It generates only one class which have all the structure (schema.cs). But i need set of classes which structure described in schema.xsd. For example: Application.cs, Applicant.cs and so on, like I have after JAXB classes generating in Eclipse.

Here is part of schema.xsd code:

    <?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2011 rel. 2 -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="3.0.0">
    <!-- Application -->
    <xs:element name="Application">
        <xs:annotation>
            <xs:documentation>Заявка</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="DecisionResponse" minOccurs="0"/>
                <xs:element ref="CreditRequest" minOccurs="0"/>
                <xs:element ref="Applicant"/>
                <xs:element ref="Routing"/>
            </xs:sequence>
            <xs:attribute ref="applicationDate" use="optional"/>
            <xs:attribute ref="timestamp" use="optional"/>
            <xs:attribute name="applicationId" type="xs:int" use="optional">
                <xs:annotation>
                    <xs:documentation>ID заявки</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="applicationDecision" type="xs:string" use="optional">
                <xs:annotation>
                    <xs:documentation>Итоговое решение по заявке</xs:documentation>
                </xs:annotation>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <!-- DecisionResponse -->
    <xs:element name="DecisionResponse">
        <xs:annotation>
            <xs:documentation>Решения по заявке</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Product" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
Gleb
  • 25
  • 5

3 Answers3

1

Your best and simple option is to use WSCF blue , it's an add-in to Visual studio just select your set of XSD files/WSDL and generate classes , then you have the option between multiple/single files and there you go

enter image description here

Coder1409
  • 523
  • 4
  • 12
0

I don't think xsd.exe has that option.

From my experience with xsd.exe, it's a great tool to get you going, but shouldn't be used like the T4 templates (e.g. .tt files for EF), but only be run once.

I've found that there are a bunch of Attributes generated that you don't need and clutter the classes.

So IMHO it's best to simply:

  • Sift through the generated schema.cs file
  • Moving sub classes that were created (e.g. Application) into new files manually
  • Remove unwanted Attributes
  • And lastly, format and rename the classes to make them maintainable for yourself (and whoever else needs to work on it)

This obviously might works best with a small or mid-sized schema.

Niels Filter
  • 4,430
  • 3
  • 28
  • 42
0

No. xsd.exe does not have an option to generate multiple classes from one xsd file.

You can try to do it programatically (See this example from Mike Hadlow)

Community
  • 1
  • 1
hdoghmen
  • 3,175
  • 4
  • 29
  • 33