This note describes a project for developing a common API for the CSS parsers in the W3C. A sample source code is already available for download ([SAC]). The software is OpenSource.
This document is a NOTE made available by the W3C for discussion only. Publication of this Note by W3C indicates no endorsement by W3C or the W3C Team, or any W3C Members. It contains a proposal for a generic API for CSS parser.
We plan to update this note according to the comments and, if there is enough interest, increases our ressources on SAC.
Comments on this document are invited and are to be sent to the public mailing list email@example.com. An archive is available at http://lists.w3.org/Archives/Public/www-style/.
This document has been produced as part of the W3C Style Activity.
A list of current W3C Recommendations and other technical documents can be found at http://www.w3.org/TR.
The goal of the project is to promote W3C technology.
One of the successes of the XML syntax was the interoperability between the XML parsers. This interoperability has been accomplished with the Simple API for XML ([SAX]). SAC plays a similar role for CSS.
The CSS specifications ([CSS1] and [CSS2]) introduce a forward-compatible grammar common to all versions of CSS. Any future versions of CSS should adhere to this core syntax, even if they add additional syntactic constraints.
The Simple API for CSS (SAC) is a proposal for a standard API for event-based CSS parsing. It is designed to support CSS1, CSS2 and future versions of CSS.
The SAC model follows the Simple API for XML ([SAX])) model:
The current proposal for SAC ([SAC]) is available in Java ([Java]) and C). A Java implementation with CSS2 support, called "flute", is also available at the same address.
This note only gives a brief outline of SAC, please refer to the online documentation for details.
The DOM Level 2 specification introduces an object model for CSS ([CSSOM]).
SAC complements the CSS Object Model:
This interface represents the parser itself. All SAC parsers must implement this basic interface. It allows applications to register handlers for differents types of events, to set the factories for the CSS selectors, and to initiate the parsing of the CSS document or a partial CSS document.The conventional solution to create instance of objects in object-oriented design is to define factory methods. Objects implementing some interface "X" are created by a "createX()".
For a complete description, please report on the documentation available on the SAC public page ([SAC]).
This is the main event-handling interface for SAC. An application will
implement call-back functions for each of these, which are then called by the
parser when the corresponding event occurs. The order of events in this
interface is important, and mirrors the order of information in the document
itself. For example, all of an @font-face rule's content (the properties) will
occur, in order, between the
startFontFace and the
Here is a partial list of the functions:
Contrary to the CSS Object Model ([CSSOM]), SAC represents the CSS selectors as objects. The SAC selectors can select any types of primary Nodes and apply a condition to these Nodes. Combinations between selectors and between conditions are also possible. SAC can express more selectors than are are currently possible in CSS1 and CSS2.
A primary Node can be:
Combinations between these selectors are:
SAC_INDIRECT_ADJACENT_SELECTOR) (@@ adjacent selectors with type node)
Note that CSS1 and CSS2 have no syntax to express selectors for other Nodes than elements and pseudo-elements, and that negative selectors and indirect adjacent selectors also do not currently exist in CSS 1 or 2.
A condition can be attached to a selector with the
Conditions can be:
Combinations between these conditions are only logical
This interface represents a lexical unit for a CSS value. All lexical unit are represented (including comma, number, string, pixel units, etc.) as well as expressions over them (e.g., "12pt/14pt" is an expression with three parts: "12pt", "/" and "14pt").
A small example for SAC is available in Java.