The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

XML metadata

It's common to store metadata as node attributes in XML docs, but if you were using an XML docs to store nothing BUT metadata, would you store that data in attributes or in the actual element nodes? ;-)

I suppose one could make the case that the metadata is “the data,” so it should be stored in text nodes, and if there is any metadata associated with the metadata being stored, then that metadata should be stored in attributes.

Or am I drinking too much coffee?
MBJ Send private email
Monday, July 03, 2006
Actually, yes, you would store it as attributes.. or metadata on metadata.

Years ago I was working at the Library of Congress on just such a project and we laid out all of the same things and it was decided to attach it there.  Here's the project:
KC Send private email
Monday, July 03, 2006
I say, you got it right :)

Your data is someone else's metadata.
hobit Send private email
Monday, July 03, 2006
It's a style thing.  Either way will work.
Posted by me...
Monday, July 03, 2006
I would go with metadata -> XML data and metametadata -> XML metadata. In the context of your XML file the metadata is going to be the primary data.

To be honest, most people don't get it right, so don't worry too much about it. Just document the fileformat you invent sufficiently and maybe make an XML Schema. Right there you're in the top 10%.

I'm having the misfortune to work with a webservice where morons invented theit own general communication transfer protocol in XML with the primary data in the attributes. They also made all identifiers some nonstandard abbrivation trying to be terse probably to conserve bandwidth on a 1Gbit line and in the documentation they have envisioned a file format that is selfdocumenting.

There are three levels of status codes where only behaviour is described in one level. The two other levels are pure guesswork. Selfdocumenting my ass.
Peter Monsson Send private email
Tuesday, July 04, 2006
It's not really that much important whether you use attributes or elements in most cases. In some cases though, when it's clear that attribute cannot cary enough structure, you will simply have to go with elements.

Either way, it's simple to write an XSLT transform "script" that will turn your elements into attributes and vice versa, so if you "make a mistake" you can always go back (you can find the code for that in the book "XSLT Cookbook" - O'Reilly).
Drazen Dotlic Send private email
Tuesday, July 04, 2006
The OP refers to the data/metadata way of deciding what goes into attributes versus content/data. It is often a subtle distinction, but remember the metadata is only metadata in relation to something, so while everything in the document may be metadata in one sense, that's not really relevant. When you decide something is an attribute based on it being metadata, it needs to be metadata *for that particular element*.

Another deciding point is whether the item can conceivably have multiples, in which case it needs to be an element, rather than an attribute, so it can be repeated.
Ben Bryant
Tuesday, July 04, 2006
I would store the metadata in an XSD document, and then just load it into a DOM for use.

You get the benefit that your XML document gets strongly-typed by the same specification that you use to define your metadata.
Wednesday, July 05, 2006
The data-metadata distinction is entirely artificial; as was pointed out, one person's metadata is another's data.  The choice between attribute and element content is sometimes forced by the rules of XML however.  For example, if what you are trying to represent needs to include leading or trailing whitespace, you must store that as an XML attribute, not element content, since XML processors remove leading and trailing whitespace from PCDATA element content.
Will Dowling Send private email
Friday, July 07, 2006
"I would store the metadata in an XSD document, and then just load it into a DOM for use."

Now that's thinking out of the box.

Thanks all.
MBJ Send private email
Wednesday, July 12, 2006

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz