jQuery in Action, 3rd edition
The moose likes Web Services and the fly likes xsd question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "xsd question" Watch "xsd question" New topic

xsd question

Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104

How can I create an xsd which allows for the following combination of input parameters to a web service:


log(userId, timestamp, time)

log(timestamp, time)

I want: userId or
userId, timestamp, time or
timestamp, time

Thanks in advance.

Peer Reynders

Joined: Aug 19, 2005
Posts: 2933
Seriously, stick to the basics and don't try to get clever with the XML Schema - this is often where some of the simpler consumer code generators run into trouble. Just because its legal XML Schema doesn't mean it's a good idea - i.e. think very carefully before you employ advanced XML schema features like inheritance, (restriction) and polymorphism, especially to mimic class inheritance trees. You are usually better off not doing it.

So stick with simple solutions like:

I.e. document that you are looking for {userId,timestamp,time}, {userId}, or {timestamp,time}, validate it in code and throw a SOAP Fault when you don't get it. Just because the XML document passes validation doesn't imply that the web service has to be able to process all the possible value combinations. This also means that later you can permit something like {userId,timestamp} without changing the web services contract.

A somewhat less simple solution:

This of course pre-supposes that the consumer code generator understands what a "choice" is.

In a schema you can specify:

In the XML document specify

A "clever" version

Now in a schema you can specify:

But in the XML document specify

However some of the simpler code generators just don't know how to deal with this stuff - and you may not want to reveal all your restrictions in your web services contract as it may adversely affect contract evolution and versioning.
Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104
Thanks Peer. I will recommend the simple root and document it. It is nice to have the other information. I will site the different ways as design alternatives, and pick the simple, straight forward way. I can talk about the pros and cons.

Your advise is once again very appreciated.

I agree. Here's the link: http://aspose.com/file-tools
subject: xsd question
It's not a secret anymore!