Is this the correct way to go about this?
OracleXMLQuery class is the Java-side implementation of DBMS_XMLQUERY APIs.
It's mostly designed to generate a canonical XML document out of a SQL query.
Assuming a query like "SELECT col1, col2 FROM my_table", the resulting XML should appear like this :
So in your test, since the resulting column is not aliased (XMLElement), you're actually trying to generate something like this :
which of course is invalid, hence the error message.
If you want to generate only <FOO>bar</FOO> as output, just use a regular PreparedStatement with your query and access the document in the ResultSet with the proper getter.
Thanks for the answer. I will post a follow up question shortly.