This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: CSS as an XML format
Feed Title: Michael Lucas-Smith
Feed URL: http://www.michaellucassmith.com/site.atom
Feed Description: Smalltalk and my misinterpretations of life
CSS is an excellent 'on the side' bonus to XML when it comes to presentation. So why isn't it an XML vocabulary in its own right?
Lets discuss possible reasons: It's easy to write than XML and when it was originally created it was made for HTML, not XML, thus, parsing CSS in its current syntax would have been easier back then than parsing XML.
Right, so now that we can parse XML very easily in just about every language under the sun, lets tackle that 'easy to write' nonsense. First off - there are no simple CSS editors out there because they have to deal with the syntax, not an XML DOM tree. Secondly, are they trying to out-do perl?: xhtml|h1.big[attribute='6'] > html|h2.small[attribute='5'] { color: red }
Lets talk practical reasons for having a CSS XML vocabulary. First a foremost, you could use CSS attributes 'class' and 'style' in -any- XML vocabulary by using a new namespace, eg:
<myTag css:class="myClass"/>
This breaks CSS away from its HTML heritage, just as W3 broke 'lang' away from its HTML heritage with the tag xml:lang.
Having it in another namespace would also help with XSLT, where you can now handle CSS easily as it is in its own namespace. You can also, as a developer, swap to your 'presentation logic' whenever you hit a CSS namespaced attribute or element.
What about definitions? There's no doubt at all that there would be more to type - if you didn't use an XML editor or a CSS XML editor. The CSS XML Editor would be much easier for vendors to create too.
Lets take an example:
h1 { color: red } would become:
<html:h1><color>red</color></html:h1>
That's not too much different. Also, we can now put that in to an XHTML document directly to apply styles where they are (much like style=, but using an actual XML element/attribute)
Another advantage: you can now change the CSS dynamically in its running environment using standard DOM methods!.
So I hope the W3 guys start catching wind of the many advantages to providing an XML vocabulary for CSS!