Converting XDR’s to XSD’s
Working in a big migration project from BizTalk 2002 to BizTalk 2006 we needed to convert all
the existing message definitions, created in XDR to XSD.
Due to the size of the current implementation (and hence the amount of schemas needed) I was asked to look at automating the process of the conversion.
The following descirbed the options considered and the conclusion reached. I'd love to hear from anyone who has any experience with this issue, to either confirm my conclusion or highlight more options.
Reusing the “Add Schema Wizard”
Since I have been experimenting in the past with reusing the logic behind the “Well Formed XML” wizard I expected this to be straight forward (and obviously the best option), I was wrong.
Apparently while the WFX and DTD wizards are pretty much external components and therefore easy to use outside BizTalk and VS (good indication to that is the fact that they need to be enabled by running a vbs script), the XDR converter seems to be embedded in the product and cannot be, so it seems, reused.
All my attempts, web searches and even using a few good contacts at MS did not bare any fruits. I could not find a way to reuse this logic.
XSD.exe claims to be able to convert XDR’s to XSD simply by passing in an XDR file as input.
However, in most my attempts, the tool generated the XSD with an additional root node - “NewDataSet” or “Schema”.
While I’m not sure why this is done, with no switches available to use with the XSD.exe in this mode I don’t see how this can be avoided.
In addition – comparing the result of the output generated by XSD.exe with the output of the “Add Generated Schema” differences are clearly visible, it seems the wizard adds some BizTalk specific nodes as annotations to help the editor work with the schema, these cannot be expected to be added by a generic tool such as XSD.exe.
This, as well as the suspicion that there might be more, less visible, BizTalk specific logic done by the wizard should direct us to look only at BizTalk specific conversion utilities as they are more likely to do the conversion to BizTalk liking.
XDR to XSD conversion tool from MS
Looking for another BizTalk specific tool I re-discovered this little gem.
This was first introduced as an external script (JS+XSL) in biztalk 2000 (before XSD was formalised), later in 2002 it was embedded into the editor and in 2004/6 seems to be used internally by the “Add Schema Wizard” (a good indication for this is that the XDRtoXSD.xsl script file still exists in the BizTalk program files folder.
The 2000 version is not at all happy with 2002 XDR’s – probably because of changes to the contents of the XDR files between versions.
The 2002 version converts the files but when added to a VS 2005 solution errors are displayed around the usage of the wildcards ##targetNamespace which causes errors due to potential ambiguity
In addition I suspect that it does not handle the biztalk specific logic in the conversion (as mentioned in the previous section around xsd.exe) as the output generated by the xsl is different then the output generated by the “Add Schema Wizard”
A Migration toolkit was provided by Microsoft to help convert BizTalk 2002 AIC components to BizTalk 2004 pipeline components and adapters.
While I have not actually tried to use the tool I went through its documentation, and it does not seem to do anything with regards to schemas.
A Migration project was introduced in BizTalk 2004 to help convert BizTalk 2002 projects to BizTalk 2004. The wizard associated with this project type does convert XDR’s to XSD’s, But I suspect it is using the same “Add Schema Wizard” logic and is not available for reuse.
Visual Studio 2005 “Create Schema” menu option
At some point down the line I’ve also looked at this option as well, although manual I hoped it will shed some light on how the process can be done. If proved possible it could have been automated using macros.
However, while it does succeeds in generating an XSD with no warnings or errors, and this XSD can even be added to a BizTalk project (and the project builds ok) the output generated differs then the one generated by the Wizard which is a cause for potential errors and therefore I believe is not a viable way forward, at least not without further more experimentation.
Based on this I came to the conclusion that the best way forward is to resort to manual conversion.
This is still relatively painless as it takes less then a minute to convert a schema, and the results are quite acceptable.
It is important to note that I did not do any deep validation of the output of the wizard, the generated XSD should be more carefully examined before concluding that it fully represents the messages expected.
If the manual process is totally an acceptable a way forward could be to investigate the differences between the output of the XSL script at the heart the MS conversion tool and the output of the “Add Schema Wizard” and either modify it to avoid the differences or wrap it in code that will.