Git Product home page Git Product logo

cascade's Introduction

Cascade

Apache 2.0 License Build Status Maven Central Javadocs

Cascade is a pure Java implementation of CSS Selectors operating on W3C DOM.

How to Use the API

Selector selector = Selector.compile("div p");
Document doc = ... /* doc is an instance of org.w3c.dom.Document */
List<Element> selected = selector.select(doc.getDocumentElement());

Features

  • Compliant with W3C Selectors Level 3.
  • Operating on standard W3C DOM interface defined in org.w3c.dom package.
  • Simple and intuitive API.
  • Optimization is performed when selectors are compiled.
  • Supports namespace.
  • Compatible with documents provided by javafx.scene.web.WebEngine.
  • Passed 700+ test cases.

For more detail, please see API documentation

Prerequisites

  • Java 8 or higher.

The library is available in the Maven Central repository. Add a dependency to your pom.xml as below:

<dependency>
  <groupId>io.github.i49</groupId>
  <artifactId>cascade</artifactId>
  <version>3.2.0</version>
</dependency>

Supported Selectors

Simple Selectors

Selector Example
Universal selector *
Type selector h1
ID selector #notice
Class selector .example
Attribute selector (presence) [title]
Attribute selector (exact match) [class="example"]
Attribute selector (space-separated) [class~="example"]
Attribute selector (dash-separated) [hreflang|="en"]
Attribute selector (prefix) [type^="image/"]
Attribute selector (suffix) [href$=".html"]
Attribute selector (substring) [title*="hello"]

Pseudo-classes

Selector Example
:root :root
:nth-child :nth-child(2n + 1)
:nth-child(odd)
:nth-last-child :nth-last-child(2n)
:nth-last-child(even)
:nth-of-type :nth-of-type(2n + 1)
:nth-of-type(odd)
:nth-last-of-type :nth-last-of-type(2n)
:nth-last-of-type(even)
:first-child :first-child
:last-child :last-child
:first-of-type :first-of-type
:last-of-type :last-of-type
:only-child :only-child
:only-of-type :only-of-type
:empty :empty
:not :not(.example)

Combinators

Selector Example
Descendant combinator h1 em
Child combinator body > p
Adjacent sibling combinator h1 + h2
General sibling combinator h1 ~ pre

Pseudo-elements are not supported.

Namespace Support

Element and attribute names can be qualified with namespaces.

SelectorCompiler compiler = SelectorCompiler.create()
        .withNamespace("ns", "http://www.w3.org/2000/svg");
Selector selector = compiler.compile("ns|circle");
Document doc = ... /* doc is an instance of org.w3c.dom.Document */
List<Element> selected = selector.select(doc.getDocumentElement());

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.