You might want to consider either providing a user interface that is an XPath directly, or else performing a simple transformation from your input string to an XPath, because then you can use XPath-style modules to assist you in the query.
-- Randal L. Schwartz, Perl hacker