tags:

views:

147

answers:

4

We are currently working on the design of a RESTful application. We have decided on XML as our basic representation. I have the following questions regarding designing/modeling the application data in XML.

  1. What are the approaches towards data modeling in XML? Is it a good idea to start from scratch and then evaluate the use of standard XML schemas or vice versa?
  2. Where can I find information on all standard XML schemas?
  3. Should I start thinking of namespaces from the onset or is it something I can postpone for later?
  4. Finally, Is it good to start from designing the XML schemas first or start with XML document and then define a schema?

Note: I have already looked at a related question at stackoverflow (What are best practices for designing XML schemas?) but that doesn't seem to address the above questions.

+1  A: 
  1. You can do a lot with XML Schema, like abstract class, enumeration etc.. See XML Schema Part 0: Primer Second Edition. If you care about interoperability, try to stay away from certain data types.
  2. List of XML markup languages lists some known schemas. For POX on REST service I think you'd be making your own.
  3. As long as it's guaranteed unique, the actual name itself doesn't really matter. Include dates in there for future versioning.
  4. I think you should have ideas of how the resulting XML document should look like first.

One thing to note about service design is that it is different from designing class/object, and you have to think more in terms of exchanging documents. This is sometimes called course-grained. In OO world, you'd be exchanging series of method calls between peers, but in SOA, you'd avoid chattiness and try to stuff most of the information needed into a document, sort of like filing a tax form.

eed3si9n
+2  A: 

If you don't have an XML already and don't know the requirements than it will be hard to design the schema first. If you have code already that has to deal with XML than it may be the best idea to take the object tree as an example for your first XML tree. They aren't that different except that XML is always just a tree and your objects not.

From then one stabilize your XML and collect requirements what use cases should be modelled with it. If you have this two you have a perfect start to do an schema. This will solidize your format.

Looking for standard schemas is always a good idea but is almost all the time frustrating, too. Postpone this until you know what your xml will look like. Maybe then you recognize there is already something standardized that is just as your format.

You should be careful about namespaces. This is a more heavy weight topic in XML because you can do so much wrong. If you are not sure that you need them then skip. That is what the rest of the world is doing. If you think you will need them start at the very first to use them. Mixing none namespace aware code and namespace aware code is a pain.

Norbert Hartl
I disagree strongly about leaving out namespaces -- this forecloses things you might not care about but which some user of your library (or customer, or future maintainer, or integration engineer) might want to do, like embedding your document inside a larger document in a different format, or embedding a different kind of information inside *your* document and expecting 3rd-party tools which know nothing about your document format to Do The Right Thing. Using namespaces is thus the safer choice for futureproofing.
Charles Duffy
Well it is just another "personal decision". You are talking about frameworks, third-party software. I don't think the odds are quite high he is talking about this. The rest of the world has simple problems. Yes, while namespaces is the right way to go it can make your work also really cumbersome. So if the use case doesn't care about this skipping namespaces is saving
Norbert Hartl
Leaving out namespaces works well for applications that don't matter. Cause and effect, or vice versa?
John Saunders
Namespaces can be a source of confusion when you need to deal with schema versioning. (I've modified the schema; do I need to change the namespace?) I think it's a price that's well worth paying, because namespaces lend a great deal of clarity both to the schema itself and to instance documents.
Dan Breslau
A: 

I agree that you should first design your application, and decide on what information you need to exchange.

As you're doing that, you may possibly find that some of the information you're exchanging comes from standard schemas. You may also find that there are standard schemas used by your customers, that already describe the information you want to exchange.

If neither of these things occurs, then forget about "standard schemas". Among other things, I don't think you're going to find a comprehensive list of them - there are too many.

John Saunders
A: 

Its better to think of namespace design approach from the start. If the XML files you are going to design are conceptually related you could go for homogeneous namespace design approach.

Heteregeneous namespace design approach allows for sharing and reusability. This could be used when you would like to visually identify domain-specific files.

The heterogeneous design approach is the recommended way. Refer http://technologyandleadership.com/three-schema-design-approaches/ to know how to implement this design approach for your project

Aruna