Skip to content

sam-rosenthal/java-cssSelector-to-xpath

Repository files navigation

java-cssSelector-to-xpath


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 Conversion Implementation Notes

  • 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.
  • 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:\\/ ]+

Dependencies

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.

Installation

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

  • 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);
    	}
    	
    

Helpful Links/More Info

Sam Rosenthal - Cornell Engineering '21

This project is licensed under the MIT License.

About

OSS to convert CSS Selector Strings to Xpath Strings

Resources

License

Stars

Watchers

Forks

Packages

No packages published