Simplier and more generic parsing using XPath #1626
Replies: 4 comments 1 reply
-
Querying specifically using a full XPath: // return only the C column based on the complete XPath
columns = JSQLFormatter.extract(sqlString, Column.class, "/Statements/selectBody/where/rightExpression/Column[2]");
for (Column column: columns) {
System.out.println("Found specific column by complete XPath: " + column);
}
|
Beta Was this translation helpful? Give feedback.
-
As I said, cool. Any reason why you do not use https://commons.apache.org/proper/commons-jxpath/? Or do you use it? When I needed something like that it worked for me. Could we integrate this in JSqlParser itself? |
Beta Was this translation helpful? Give feedback.
-
I don't feel like JXPath was a good option. |
Beta Was this translation helpful? Give feedback.
-
Actually, you are right that we should keep JSqlParser jar independent from third party libs. And you are right, JXPath is quite an old lad. ;) Still it works. |
Beta Was this translation helpful? Give feedback.
-
Example SQL
Can be simply queried via XPath:
Output
Based on the Parsed Object Tree:
I believe this was a much easier way to quickly query or access Objects of a SQL statement instead of writing the Listeners.
The code above works nicely in JSQLFormatter already -- do we want to port it into JSQLParser directly?
Beta Was this translation helpful? Give feedback.
All reactions