title: How to convert xml text stored in a VARCHAR and select using XQUERY expression
body: <p>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.</p>
  
  <p>An example document looks like:</p>
  
  <pre><code>&lt;a&gt;
     &lt;b foor="bar"/&gt;
     &lt;c/&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>My query looks like:</p>
  
  <pre><code>SELECT XMLQUERY('//c' PASSING 
    XMLCAST('&lt;a&gt;&lt;b foor="bar"/&gt;&lt;c/&gt;&lt;/a&gt;' AS XML)) 
  FROM SYSIBM.sysdummy1
  </code></pre>
  
  <p>But instead of returning a  element I get the following error message:</p>
  
  <blockquote>
    <p>SQL Error [10507]: The Context item in an axis step must be a node. SQLCODE=-16012, SQLSTATE=10507</p>
  </blockquote>
  
  <p>How can I get this to work?</p>
  
  <p>===========================================<br/>
  <strong>Update #1:</strong>
  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:</p>
  
  <pre><code>SELECT 
      XMLCAST(XMLQUERY('string(/a/b/@foo)' PASSING X) AS VARCHAR(20)) 
  FROM (
  SELECT xmlparse('&lt;a&gt;&lt;b foo="bar"/&gt;&lt;c/&gt;&lt;/a&gt;')
  FROM sysibm.sysdummy1
  ) AS X(X)
  </code></pre>