|
|
Updated 4/01/08
Next update: ~06/01/08
Next update includes support for style declarations and property values.
This is a CSS3 parser written in ActionScript 3.0. In its current state, it's best used to query XML documents with CSS3 selectors as you would using XPath. The parser can handle full CSS declarations, but property handling is incomplete.
Example:
import com.newgonzo.commons.css.CSSSelectorQuery;
var xml:XML = <node>
<child name="test"/>
</node>;
var query:CSSSelectorQuery = new CSSSelectorQuery("child[name^='te']");
var result:XMLList = query.exec(xml);
trace(result.toXMLString()); // traces <child name="test"/>For details on the CSS3 Selectors spec, visit the W3C.
In subversion you'll find:
src/
The CSS parser and DOM. The parser is an implementation of The Simple API for CSS (SAC).csstester/
A Flex app for testing selectors. Try it here.parsertest.fla
A Flash CS3 document that executes and traces results on a handful of tests.
Selectors supported:
* E E[foo] E[foo="bar"] E[foo~="bar"] E[foo^="bar"] E[foo$="bar"] E[foo*="bar"] E:root E:only-child E:only-of-type E:empty E.warning E#myid E F E > F E + F E ~ F
Selectors to be supported:
E[hreflang|="en"] E:not(s) E:first-child E:last-child E:nth-child(n) E:nth-last-child(n) E:nth-of-type(n) E:nth-last-of-type(n) E:first-of-type E:last-of-type
The parser probably needs to be optimized, and I'm considering adding a second pass to it to make it easier to leverage E4X for complex selectors.
To do:
- finish the remaining selectors and pseudos
- fix namespaces
- work out property values and style declarations
- complete the document handler and related parse events
- write more tests
- documentation
You're welcome to contact me at john at newgonzo dot com.
