Combining Multiple XSD Files into One Schema

All,

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

Thanks,
John

criminal.xsd
evictions.xsd
rapidbuyrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
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:complexType>
                  <xs:sequence>
                        <xs:element ref="tns:stats"/>
                        <xs:choice>
                              <xs:element ref="tns:recordset"/>
                              <xs:element maxOccurs="unbounded" ref="tns:record"/>
                        </xs:choice>
                  </xs:sequence>
            </xs:complexType>
      </xs:element>

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.