I am working on a program that gives the user the opportunity to define his own selection string. For example in the expression:
doc.select("a[href]");
The user would have specified the “a[href]” part. Now my question is, how can I check if the passed in string is a valid JSoup selector string? Does anyone know how to validate this?
Any help would be very much appreciated.
Thanks
approach 1: Edit the Jsoup source and make the Parser public or implement your own method there
approach 2: Parse a simple dummy element and catch the exceptions. if one is thrown: query is not valid, else it’s ok. Not the best solution but it works.
Here’s an example:
Test:
Testresult: