SQLxD Part 4 — Selectors

This is the fourth part of the SQLxD series. For your convenience you can find other parts in the table of contents in Part 1 – XML Transformation

Now we can implement classes representing multi-part identifiers. We start with the following:

This selector providers us an abstraction of selecting nodes from root. We start with top level selector which extracts element only if its name is as specified:

Next, we can go one level deeper:

We can also extract any children with specified name:

Finally, we can recursively use selector for all children:

This is great, we also need chain of selectors:

And we are done. Now if we want to extract SELECT * FROM table we use the new TopLevelSelector("table"); selector, if we want to represent t.table2, we use new ChainedSelector(new TopLevelSelector("table"), new NodeSelector("table2"));.