Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool that can combine many XSD files into one?

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

like image 532
ewall Avatar asked Oct 04 '10 21:10

ewall


People also ask

How do I add XSD to XSD?

xsd" /> where 'res' is a folder where the XSD is residing and this folder is at the same level of the folder from where you are referencing it. If you are giving Absolute path, then you need to write <xs:include schemaLocation="file:D:/workspace/Test/res/header.

What is XSD tool?

The XML Schema Definition (Xsd.exe) tool generates XML schema or common language runtime classes from XDR, XML, and XSD files, or from classes in a runtime assembly.

What program opens XSD files?

The file can also open with Microsoft Visual Studio, XML Notepad, EditiX XML Editor, Progress Stylus Studio, and XMLSpy.


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

like image 135
Sandhya Avatar answered Sep 30 '22 14:09

Sandhya


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.

like image 37
Petru Gardea Avatar answered Sep 30 '22 12:09

Petru Gardea


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.

like image 40
ewall Avatar answered Sep 30 '22 13:09

ewall


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.

like image 34
Syed Musa Tariq Avatar answered Sep 30 '22 13:09

Syed Musa Tariq


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.

like image 27
TheKingpin Avatar answered Sep 30 '22 13:09

TheKingpin