Coder Social home page Coder Social logo

cssselectorconverter's Introduction

CSS Selector Converter

A CSS Selector to XPath Selector for Objective-C. Support mostly used subset of CSS Selector Level 3.

I build this converter so that I can use .class instead of //*[contains(concat(' ', normalize-space(@class), ' '), ' class ')] in IGHTMLQuery.

Usage

#import "CSSSelectorConverter.h"

CSSSelectorToXPathConverter* converter = [[CSSSelectorToXPathConverter alloc] init];
[converter xpathWithCSS:@"p" error:nil];
// => "//p"

[converter xpathWithCSS:@"p.intro" error:nil];
// => "//p[contains(concat(' ', normalize-space(@class), ' '), ' intro ')]"

Status

It supports following CSS Selectors:

*                                "//*"
p                                "//p"
p.intro                          "//p[contains(concat(' ', normalize-space(@class), ' '), ' intro ')]"
p#apple                          "//p[@id = 'apple']"
p *                              "//p//*"
p > *                            "//p/*"
H1 + P                           "//H1/following-sibling::*[1]/self::P"
H1 ~ P                           "//H1/following-sibling::P"
ul, ol                           "//ul | //ol"
p[align]                         "//p[@align]"
p[class~="intro"]                "//p[contains(concat(\" \", @class, \" \"),concat(\" \", 'intro', \" \"))]"
div[att|="val"]                  "//div[@att = \"val\" or starts-with(@att, concat(\"val\", '-'))]"

It supports following pseduo classes:

  • first-child
  • last-child
  • first-of-type
  • last-of-type
  • only-child
  • only-of-type
  • empty

Currently pseduo classes with parameters are not supported (I probably will not implement them until I really NEEDS them):

  • nth-child()
  • nth-last-child()
  • nth-of-type()
  • nth-last-of-type()
  • not()

Following pseduo classes will not be supported:

  • Dynamic pseudo classes (:link, :visied, :hover ... etc)
  • UI elements states pseudo-classes (:enabled, :checked, :indeterminate)
  • :target
  • :lang
  • :root

Development

Building the project

  1. Install cocoapods
  2. Install pods: pod install

License

MIT License. See License.txt.

cssselectorconverter's People

Contributors

siuying avatar aporat avatar olegam avatar

Stargazers

Liuxb avatar  avatar Gustavo avatar  avatar Liu Lantao avatar  avatar scott avatar wuyong avatar Jake Marsh avatar Pierre Rougeot avatar  avatar 平江 avatar  avatar Jason Patterson avatar  avatar yohei sugigami avatar Tim Sullivan avatar Sébastien Hamel avatar YangLe avatar  avatar Jorge (Hezi) Cohen avatar Katsuma Tanaka avatar Steven Zhang avatar David Chang avatar

Watchers

 avatar James Cloos avatar  avatar

cssselectorconverter's Issues

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.