SizzleUser Guide
Overview
Sizzle
is a library for querying XML documents by means of CSS selectors, and aims to be CSS2.1 compliant.
Sizzle
currently supports:
- The Universal selector -
*
- Type selectors -
div
- ID selectors -
#id
- Class selectors -
.heading
- Descendant selectors -
html div
- Child selectors -
html > div
- Adjacent sibling selectors -
div + p
Sizzle
hopes to support attribute selectors and the :first-child
pseudo-class soon.
The following selectors can not / will not be supported:
- The link pseudo-classes
:link
and:visited
can not be supported because they refer to a DOM model. - The dynamic pseudo-classes
:hover
,:active
, and:focus
can not be supported because they require user input. - The language pseudo-class
:lang
will not be supported because its usefulness is questionable. - The Pseudo-elements
:first-line
,:first-letter
,:before
, and:after
can not be supported because they do not select XML elements.
Install
Install Sizzle
with the Fantom Respository Manager ( fanr ):
$ fanr install -r http://repo.status302.com/fanr/ afSizzle
Or to install manually, download the pod from Status302 and copy it to %FAN_HOME%/lib/fan/
.
To use in a Fantom project, add a dependency to build.fan
:
depends = ["sys 1.0", ..., "afSizzle 0+"]
Quick Start
1). Create a text file called Example.fan
:
using afSizzle class Example { Void main() { xml := """<html><p class="welcome">Hello from Sizzle!</p></html>""" elems := Sizzle().selectFromStr(xml, "p.welcome") echo(elems.first.text) // -> Hello from Sizzle! } }
2). Run Example.fan
as a Fantom script from the command line:
C:\> fan Example.fan Hello from Sizzle!
Usage
Sizzle
usage is fairly simple and self explanatory; XML document in, XML elements out.
SizzleDoc contains compiled and cached document information and is intended for re-use with multiple CSS selectors:
doc := SizzleDoc("""<html><p class="welcome">Hello from Sizzle!</p></html>""") elems1 := doc.select("p.welcome") elems2 := doc.select("html p")
Currently, whitespace around child and sibling selectors is mandatory, meaning:
div > p
is validdiv>p
is NOT valid
Release Notes
v0.0.2
- New: Preview Release