BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


Schemas, xsd, xdr


 
 

<< reBloggerSEO >>
 


By Silvester Rößner
First Posted 12/07/2006
Times viewed 348

XSD Merger


This post contains attachments
v20061207021321.zip 

Summary You have a bunch of XSD schema files but want only a single XSD file? This little helper does this very task in two simple steps

XSD Merger

 

 

The merger consists of two XLST files that transform a bunch of related XSD files in one single XSD file. Since I haven't found a way to do this in one step, you have to do it in two. Sorry ;)

Application
  • Build different versions of specialized XSD files of a set of primary XSD files. This simplifies maintenance.
  • Use one XSD file instead of a bunch of XSD files. You then can easy search for an element. This (may) also reduce load time.
Preconditions
  • The XLST can handle only one namespace. So the XSD files must all belong to one single namespace. That's what I mean with "related XSD".
  • You must create two directories, one for each step of the translation. That's because the merged file has the same name as the root XSD file. Without directories the first step would overwrite your root XSD file. I haven't tested what the result of the second step would look like in this case. But I don't think you liked it.

You can use my sample XMLSpy project Generic.spp as a guide. If you use it, you have to create the subdirectories "Pre Merged" and "Merged".

First Step
  • Translate the root xsd file to a subdirectory. Use the XSD-Merger-Step-1-2.xslt for this first step. The result will be a single xsd file with the same name as the root XSD file.

But be aware: the result of the first step is not a valid xsd file. This is normal!

If you use the XMLSpy project, simply add your main XSD file to the project folder "Schemas", right click on your file and select "XSL Transformation". The XSD-Merger-Step-1-2.xslt is associated with this folder and the output goes into "Pre Merged".

Second Step
  • Translate the result from the first step to another subdirectory. Use XSD-Merger-Step-2-2.xslt to do this. Now the result is valid and equal to the multiple file representation.

If you use the XMLSpy project, simply right click on the folder "Pre Merged" and select "XSL Transformation". The XSD-Merger-Step-2-2.xslt is associated with this folder and the output goes into "Merged".

Reason for developement

I have developed the merger for one reason. I have xml schemas that consist of many xsd files. If you search some specific element, you must do this by hand with the XMLSpy. You really have to open the "Schema design view" and dive into the tree structure. You can not use "Find" to do the job - at least I haven't found a way to do it.

I tried to search in the xsd files directly. But I have found that there are similar xsd files which define the same elements. And you don't know which one of them the main xsd include. So this attempt does not work either.

The best way to do the job would be to merge all included stuff into one simple xsd file. Like the c-preprocessor can do with #include. Then you can search this file with "Find" and know that you find the right thing.

But I haven't found a tool.

Implementation Background

Two steps are necessary because XSLT does not support variables in the usual way. And I haven't found a way to remember all the files I have imported already. But this would be necessary to avoid multiple definition of Xschema types.

The first step recursively includes all included XSchema files in one huge file. I embrace the included content with the tag . This tag has an attribute called schemaLocation. So it is normal that the same file is included many times.

In the second step I throw away all duplicates. I use the from the 1st step for this purpose. The value of schemaLocation is unique for each file. In other words: the same file has a unique value of schemaLocation no matter where and how it was included.

 


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< reBloggerSEO >>
 





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML