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...
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.
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.
The file can also open with Microsoft Visual Studio, XML Notepad, EditiX XML Editor, Progress Stylus Studio, and XMLSpy.
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.
<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 :)
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.
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.
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...
It seems to work just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With