Tool that can combine many XSD files into one?

May 2024 · 3 minute read

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...

2

5 Answers

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 :)

1

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.

0

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.

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.

2

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...

  • open up the .xsd that you are talking about...
  • Menu Item called ( Schema Design ) has an item called ( Flatten Schema ).
  • 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.

    ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoanFtaWh%2BenvTqKalZaSdrrV5wpqlZpufoq%2BqusRmpJqmqWLFtLCMn6ClnaNitq%2FAzmamp50%3D