• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Mapping different XML documents to a single database schema?

 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I have a request processing system which receives slightly different XML messages from different sources (client applications). The requirement is that every request needs to be logged into a database. Now, the question remains, how should I design the database schema for storing these log entries when one complex element in the incoming requests varies?
Of course I could have a table per different "variant" section, but I wouldn't want to go there because the number of these variants may grow over time causing maintenance headache.

Here are two example requests that should be possible to handle (the exact XML schema is not written in stone, though). Basically, the DTD for these requests would specify something like <ELEMENT request (securitycode, country, model, (sms | ivr))> where there's always either an "sms" or "ivr" element (and possibly something else in the future) and the contents of these alternatives are different.

 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you log them for? How do you need to retrieve them?
Could you simply write the XML into a CLOB/BLOB?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What do you log them for? How do you need to retrieve them?

I don't know... I will after 3 hours when I have a chance to discuss with the customer. I'm basically doing research on the alternative approaches for each scenario.

Could you simply write the XML into a CLOB/BLOB?

Yes, I could. And that's what I'll probably end up doing unless the customer has something in mind for the future. Based on what we know right now, the simplest thing would be to add two columns into the existing table and simply leave the other column unused for half of the requests.
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMHO, I would avoid the whole BLOB/CLOB thing if possible. You pretty much kill any searchability and flexability by doing this. Based on the examples you gave, I might think about something like this:

Given the above schema, your populated tables might look like this given your data:

So yeah, you have more than one table, but it's not a big deal if you need to add additional variants other than SMS or IVR in the future, since you can see how all these sections are joined to the main request. Just add a new table, with a foreign key field for the REQUEST_ID, for any new sections that come along.
[ December 01, 2003: Message edited by: Jason Menard ]
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic