Java tool for transforming CSS Selector strings to XPath strings.
Visit the website that implements this tool.Need a 2021 Cornell University graduate?
- CSS Selector To XPath has been implemented for all Simple Selectors and Combinators.
- The following subset of CSS Selector Pseudo-Classes have been implemented:
- :empty, :first-child, :last-child, :only-child, :first-of-type, :last-of-type, :only-of-type
- (*NEW*) :nth-child(expr), :nth-last-child(expr), :nth-of-type(expr), :nth-last-of-type(expr)
expr = {odd | even | xn+y, where x and y are integers}
- Not all Pseudo-Class CSS Selectors can be converted to XPaths.
- A possible future enhancement is to implement more Pseudo-Classes.
- Chrome Browser was used as reference implementation.
- All base CSS Selectors and corresponding XPaths were tested cases using Chrome Browser's Developer Tools.
- Additional restrictions
- All names and values (Elements and Attributes) are case sensitive
- Element names and Attribute names are restricted to the following regular expression: -?[_a-zA-Z]+[_a-zA-Z0-9-]*
- Attribute values are restricted to the following regular expression: [-_.#a-zA-Z0-9:\\/ ]+
This project is a pure jave applicication/API. It requries Java JDK 8 and no external jars. Within this project's baseline, there is a web-based implementation that depends on React and Spring Boot . I consider the webpage an example implementation of this project. As a result, I don't consider the dependencies for the website a requirement for the OSS.
To create the project's jar file, run the following maven command:
mvn -f pom.javaCssSelectorToXpath.xml install
The jar file will be installed in target subdirectory and the name will include the corresponding version number of this project
- Usage as a Java Application:
java -cp org.sam.rosenthal.java-cssSelector-to-xpath-<version number>.jar org.sam.rosenthal.cssselectortoxpath.utilities.CssElementCombinatorPairsToXpath <CSS Selector String> - Converts a CSS Sector String to a Xpath String java –cp org.sam.rosenthal.java-cssSelector-to-xpath-<version number>.jar org.sam.rosenthal.cssselectortoxpath.utilities.CssElementCombinatorPairsToXpath -v{ersion} - Displays the version number of java-cssSlector-to-xpath Java –cp org.sam.rosenthal.java-cssSelector-to-xpath-<version number>.jar org.sam.rosenthal.cssselectortoxpath.utilities.CssElementCombinatorPairsToXpath -h{elp} - Displays this help usage text
- Usage as a Java method call:
public String convertCssSelectorToXpath(String cssSelector) throws CssSelectorToXPathConverterException { return new CssElementCombinatorPairsToXpath().convertCssSelectorStringToXpathString(cssSelector); }
- Cascading Style Sheets-Wiki
- XPath-Wiki
- XPath/CSS Equivalents
- MDN web docs CSS Selectors
- MDN web docs XPath
- W3Schools CSS Reference
- CSS Tricks Almanac
- Evaluate and validate XPath/CSS selectors in Chrome Developer Tools
This project is licensed under the MIT License.