Tool that can combine many XSD files into one?
Asked Answered
A

5

26

I need to create XML serializer classes for approximately 65 XSD files, for which I am using Microsoft's XSD.EXE to generate the C# code...

However, I keep running into Window CMD's character limit in the resulting output file (in which XSD.EXE combines the name of every XSD included): "The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."

To make a long story short, it seems that the only way I can get all these to validate and generate together is if I can merge all the XSDs (de-referencing the includes/imports, which XSD.EXE doesn't resolve the schemaLocation anyway) into one big one.

Please tell me that there exists a tool to do this...

Alicealicea answered 4/10, 2010 at 21:34 Comment(2)
Have you tried LINQ to XSD? It's a nice replacement to XSD.EXE linqtoxsd.codeplex.comMaurita
@Artem K -- No, I hadn't heard of LINQ to XSD before. I'll take a look.Alicealicea
I
32

What you can do is to create another new file called file.xsd containing all the schema names in it and then the trick is to name the last schema file with .\ as prefix.

File.xsd

<xsd xmlns='http://microsoft.com/dotnet/tools/xsd/'>
    <generateClasses language='CS' namespace='MyNamespace'>
        <schema>First.xsd</schema>
        <schema>Second.xsd</schema>
        <!-- more schema files here -->
        <schema>.\Third.xsd</schema>
    </generateClasses>
</xsd>

Now run the command “xsd.exe /p:file.xsd /classes” and you get the class file generated :)

Innominate answered 8/4, 2013 at 6:10 Comment(1)
You don't even need to create the file.xsd, adding `.\` to the final file on the command line also works.Bedesman
I
16

For future references, another tool designed for XML Schema refactoring is QTAssistant - I am associated with it.

To clarify your question and hopefully help others... One thing that cannot be achieved as requested by you is that one cannot de-reference imports: an XSD file is associated with one XML Schema which doesn't allow more than one target namespace per xsd:schema element.

An xsd:include can be "inlined"; since files must have the same target namespace or match the "chameleon" namespace design approach, it is possible to merge the content of a file into the other.

An xsd:import cannot be "inlined"... unless you refactor target namespaces as well. However, this would not produce an equivalent schema set.

If you have a fully defined XML Schema set authored across 65 XSD files, with say 10 namespaces, the "canonical" set of re-factored XML Schema files has to have at least 10 files in it.

Iceni answered 9/8, 2011 at 18:20 Comment(0)
A
7

I did locate a tool (basically an XSLT) for doing this kind of thing: Paul Kiel's XML Schema Flattener, but I haven't got my hands on it yet.

Other sources say that tools like Oxygen XML Editor and XMLSpy can do it too, but I can't figure out how.

-> http://www.oxygenxml.com/xml_schema_editor.html#xml_schema_flatten

In my case, I solved the problem via another circuitous route: shortening the name of each input XSD so that XSD.EXE's combined output name--which you can't choose--is below the 260 character limit.

Alicealicea answered 6/10, 2010 at 18:14 Comment(0)
S
7

Just add .\ prefix with the name of last .xsd(schema) file and enclose it in commas e.g ".\last.xsd". The output class will be generated with the last schema file name.

Sweatt answered 14/1, 2015 at 13:36 Comment(2)
It's crazy that this works, but it's also crazy that XSD behaves like this in the first placeStorax
A valid example xsd Base_Types.xsd Catalog_Types.xsd ".\Data_Fin.xsd" /c /n:Data_FinBackpack
N
4

I just started using Altova XML Spy ( 1 day )

To flatten .xsd schema into one document... that will still validate, and supply references to click in eclipse...

  1. open up the .xsd that you are talking about...
  2. Menu Item called ( Schema Design ) has an item called ( Flatten Schema ).
  3. Click it. ( it will ask you where to save the new file... I just create an output folder or something.

It seems to work just fine.

Neolithic answered 21/10, 2011 at 22:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.