Robin Berjon

XML Bad Practices

Naming Without Context

One of the great things about trees is that they provide natural context for content. And when people edit content inside a tree, they are aware of that context. That is the reason why an author will know that a title element inside a circle element will be the title for that circle, and not for the entire document.

Failing to use context in naming elements or attributes entails a loss in language fluidity. Some vocabularies that have strong roots in SGML have an excuse for this approach since DTDs named elements globally. This is visible in DocBook for instance: it feels daft to call every item in a list a listitem since it appears as the child of one of DocBook's many list elements, but that was necessary in those days from before broadcast radio and widespread tap water.

More recent languages have no such excuse. For instance SVG has a long list of elements beginning with "fe": feDistantLight, feSpotLight, feColorMatrix, feConvolveMatrix, feGaussianBlur, feTurbulence... That "fe" is meant to signify "filter effect". But the fact is that these elements can only appear as children of the filter element — they are always going to be in a filter effect defining context. The prefix just makes them more clumsy, as if all SVG elements began with "svg".

This article is part of a series on XML Bad Practices.