IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Recommended XML structure?
We're writing a DTD, and there are two ideas in play: Nested, hierarchical format; or flattened out with cross-references. Here's what I mean.

A package may include one or more products, or none. Each product can have one or more options, or none. Each package, product or option may have a price.

First option, nested hierarchical (using square brackets):
[order]

[package]
[packageID/]
[price/]
[product]
[productID/]
[price/]
[/product]
[product]
[option]
[optionID/]
[price/]
[/option]
[option]
[optionID/]
[price/]
[/option]
[/product]
[/package]
[/order]


Second option, flattened with cross-references:
[order]

[package]
[packageID/]
[price/]
[/package]
[product]
[productID/]
[packageID/]
[price/]
[/product]
[product]
[productID/]
[packageID/]
[optionID/]
[price/]
[/product]
[product]
[productID/]
[packageID/]
[optionID/]
[price/]
[/product]
[/order]


First option advantages:
* Logical, intuitive structure
* Simple to transform with XSL
* Easy to grab metadata -- like "count(products)"

Second option advantages:
* Easy to generate from DB
* Easy to loop through with procedural languages
* Known maximum depth of nesting

I've got my preference. Anybody got some good arguments one way or the other (or links to them)?
--

Drew
New I'd be asking what the purpose is of the XML.
If it's an intermediate between two apps or databases, then pick the format that is easiest to process. Or, more likely, a compromise between easiest to generate and easiest to process. I imagine this is going to be more like your cross-reference format.

OTOH, if the XML data is more authoritative, I would say you can be more idealistic, which means the heirarchical format. I'd be wary of duplicated nodes with that, however, and how consuming code is supposed to deal with that.

Wade.
Static Scribblings http://staticsan.blogspot.com/
New I agree
I agree, with the addition that if the data is being assembled to send between companies, then go with the format that is most easily understood, most clearly documented and which is least likely to have internal data inconsistencies. All of those criteria favor the nested version.

One additional advantage to the nested format is the data is physically closely associated. This reduces time going back and forth across the file/disk to find data, which can be the biggest delay when the file is too big to fit into memory.

Jay
New Silly question
why a DTD?

Wait a second...first back up more...do you need to do validation? If not, you don't HAVE to define an XSD or DTD. Useful if the XMLs are all internal. (I still recommend the XSDs, but I know a number of companies that don't define their XMLs so that they can change them on the fly)

Then, if you're needing to to do validation, why not XSD?

Depending on what makes up an option/prices I might consider moving these to attributes.

Also, I'd probably go with the nested hierarchical. Cross-references are easier to generate DB-wise and all...but once you start leveraging the XML via XPath/XSLT, you'll find you want to add in new fields, whatever, and you'll get burned with the cross-references in long-term maintenance.
New Hmm ...
DTD vs. XSD I hadn't thought about. I was using the term DTD loosely to mean "how will we structure the XML?"

Whether we need to validate or not, the code that consumes the XML needs to know what to look for, so the structure still needs to be defined IMO.

Your last paragraph basically sums up my feeling on it. We're using XLST heavily, and I've had to learn a few things about it that I'd rather not know. Like for instance: variables are immutable, but you can simulate them by creating a recursive template. Yes, XSLT supports recursion.

One of the main problems with using the cross-references is you can't just define a template and a match criterion. You have to roll your own loops. Total pain in the ass. Plus you have to select all the non-nested values and pass them into the template as parameters.
--

Drew
     Recommended XML structure? - (drook) - (4)
         I'd be asking what the purpose is of the XML. - (static) - (1)
             I agree - (jay)
         Silly question - (S1mon_Jester) - (1)
             Hmm ... - (drook)

I enjoy this motorcade and will recommend it to my niece.
52 ms