title: XPathReader error: java.lang.String cannot be cast to org.w3c.dom.Node
body: <p>I am trying to parse data from XML that has been obtained from a <code>Clob</code> type. For some reason, I am getting this exception... I can't figure out why. I have obtained the Clob from an oracle database column that contains an <code>XMLType</code> value, that is the XML. I have successfully extracted the XML contained from the <code>XMLType</code> to a <code>Clob</code> type. This is obtained with the following code:</p>
  
  <pre><code>xmlBean =  XmlHelper.xPathRead(film.getXmlClob());
  </code></pre>
  
  <p>the <code>film</code> object is in the model if you will, and the <code>getXmlClob()</code> method returns a <code>Clob</code> value that contains the XML I want to parse using XPath. Here is the rest of the code:</p>
  
  <p><strong>XMLHelper</strong></p>
  
  <pre><code>public static XmlBean xPathRead(Clob xmlClob) {
      XPathReader reader = new XPathReader(xmlClob);
      XmlBean xmlBean = new XmlBean();   // just an entity from the model to store the xml's contents inside
  
      String filmId = "/IMAGE[1]/@id";
      xmlBean.setFilmId(Integer.parseInt((String) reader.read(filmId, XPathConstants.STRING)));
  }
  </code></pre>
  
  <p><strong>XPathReader</strong></p>
  
  <pre><code>public class XPathReader {
      private String xmlString;
      private XPath xPath;
  
      public XPathReader(Clob xmlClob) {
  
          try {
              if ((int) xmlClob.length() &gt; 0) {  
                  String s = xmlClob.getSubString(1, (int) xmlClob.length()); // this is a way to cast a CLOB into a STRING
                  this.xmlString = s;
                }
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          xPath = XPathFactory.newInstance().newXPath();
      }
  
      public Object read(String expression, QName returnType) {
          try {
              XPathExpression xPathExpression = xPath.compile(expression);
              return xPathExpression.evaluate(xmlString, returnType);
          } catch (XPathExpressionException ex) {
              ex.printStackTrace();
              return null;
          }
      }
  }
  </code></pre>
  
  <p>Any ideas? The problem resides in the <code>evaluate()</code> method...</p>
  
  <p><strong>Error message</strong></p>
  
  <blockquote>
    <p>java.lang.ClassCastException: java.lang.String cannot be cast to
    org.w3c.dom.Node  at
    com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.eval(Unknown
    Source)   at
    com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.eval(Unknown
    Source)   at
    com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.evaluate(Unknown
    Source)   at helper.XPathReader.read(XPathReader.java:34)     at
    helper.XmlHelper.xPathRead(XmlHelper.java:325)</p>
  </blockquote>