Combining Multiple XSD Files into One Schema

Posted on 2011-10-31
Last Modified: 2012-08-14

We have a server application that can return one of 5different XML responses to a caller. These responses are described by separate XSD files. Let's call them A.xsd, B.xsd, C.xsd, D.xsd and E.xsd. We have control of the namespace, etc., so that does not represent an issue.

Now, I want to take the 5 different XSD files and create a single XSD that can be used to validate any of the messages (A, B, C, D or E).

How would I go about building a single XSD that accomplishes this?

I have looked at using complexType, choice, etc., but the options are confusing.

I have attached 2 of the XSD files that I'd like to combine into one...


Question by:rapidbuyr
    1 Comment
    LVL 60

    Accepted Solution

    Well, this is a bit a tricky task.
    In fact you more or less need to do the modelling all over

    In a first view you can throw all stuff together
    The structure is almost the same and the main difference is that a "Response" has a "recordset" with a number of "tns:Result" as child for criminal.xsd and a number of "record" in evictions.xsd

    You could add a choice

    <xs:element name="Response">
                            <xs:element ref="tns:stats"/>
                                  <xs:element ref="tns:recordset"/>
                                  <xs:element maxOccurs="unbounded" ref="tns:record"/>

    so this now covers both xsd.

    But, the model for tns:stats/tns:searchInput is different. Also there you could make a choice between the complex type of the simple string type one way or another.
    So you can make a combined model, BUT
    ... something you can't model is that tns:stats/tns:searchInput should be a simple string when there is a recordset, and have a somewhat more complex model when there are multiple records
    That is a co-occurence constraint, and that can't be modelled in a xsd, without help from schematron

    So bringing to schemata together already gives a less strict schema over having two different schemata,
    I am not sure how acceptable that is

    I hope you understand this would even get worse with 5 schemata

    Please consider carefully why you want to do this.
    I have a feeling that it would be more powerfull to guess teh schema from the result that comes in
    and dynamically attach the correct schema to your XML.
    It is going to be a lot more robust
    In order to get it right, you are in for a complex redesign (if at all feasible, I have only seen two of the 5 schemata)

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
    For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now