I have xml documents stored as text in a VARCHAR column. I'd like to convert the text to XML documents in order to perform XQUERY selects on the documents.
An example document looks like:
<a>
<b foor="bar"/>
<c/>
</a>
My query looks like:
SELECT XMLQUERY('//c' PASSING
XMLCAST('<a><b foor="bar"/><c/></a>' AS XML))
FROM SYSIBM.sysdummy1
But instead of returning a element I get the following error message:
SQL Error [10507]: The Context item in an axis step must be a node. SQLCODE=-16012, SQLSTATE=10507
How can I get this to work?
===========================================
Update #1:
Just in case anyone stumbles upon the same problem. At least in my environment the queries below work but instead of returning the text of the matching xml nodes I only got columns showing up as value "[le]". I had to cast the result to e.g. VARCHAR XMLCAST() to get the xml as text. So I changed Stavr00's query to:
SELECT
XMLCAST(XMLQUERY('string(/a/b/@foo)' PASSING X) AS VARCHAR(20))
FROM (
SELECT xmlparse('<a><b foo="bar"/><c/></a>')
FROM sysibm.sysdummy1
) AS X(X)