Entities in XML (Re: New version of the Selectors module of CSS3)

Jonas Sicking writes:
> Bjoern Hoehrmann wrote:
> 
> > | 5. entities
> > | If I have a XML file containing unresolved entities it could be really
> > | useful to be able to style those.
> 
> > No problem. Wrap them in an inline element.
> 
> I don't want to adjust my XML for display. The usecase is:
> I have an XML file containg some data. The markup is not designed for
> display but rather for the data it contains. To be able to display the data
> I want to use CSS. The markup contains some entities that have special
> meanings, such as &null; could mean that data is not availible, &error;
> means datacalculation resulted in an error.
> Lets say I have the following XML file:
> <person>
>   <name>Mr Foo</name>
>   <age>&null;</age>
>   <income>&error;</income>
> </person>
> 
> I could use this CSS
> 
> :root { font-family: sans-serif }
> person {display: block; padding: 2em; border-bottom: 2px solid black}
> name { font-size: 200%; text-decoration: underline; display: block; margin
> 1em;}
> age,income { display: block; }
> &null; { content: 'Data not avalible'; color: gray }
> &error; { content: 'Error'; background: red }
> 
> Maybe I'm just not using entities correctly. This might not at all be the
> purpos they were designed for.

Entities may be useful to the author, to make changing certain parts
of a document easier or to make the document shorter, but they are not
meant to convey any semantics to the reader. An entity is simply a
macro. If an entity "&foo;" is defined as "bar" then to the reader
there is absolutely no difference between the documents

    <elt>&foo;</elt>
and
    <elt>bar</elt>

If you need metadata, you have to use elements or attributes. E.g.:

    <person>
      <name>Mr Foo</name>
      <age><null/></age>
      <income><error/></income>
    </person>
or
    <person>
      <name>Mr Foo</name>
      <age null="y"></age>
      <income error="y"></income>
    </person>

Of course, XML is just a syntax, and you could use it in any way you
want. But you may encounter difficulties, since most XML tools
(parsers, transformation tools, renderers, etc.) implicitly assume a
certain way of using XML. E.g., as you discovered, CSS has no way of
styling an entity, since it assumes it only ever has to render the
expansion of the entity.



Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos/                              W3C/INRIA
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France

Received on Monday, 9 October 2000 05:52:46 UTC