Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Extracting elements from an xml string - org.apache.xerces.dom.DeferredText

843834Mar 4 2002 — edited Aug 30 2006
Hello all,

I am new to xml, and I thought I had a handle on things until I got this problem...I am getting an xml string from the body of an e-mail message, and then I am trying to extract elements out of it. Here is an example xml string:
<?xml version="1.0" encoding="UTF-8"?>
<filterRoot>
   <filter action="MOVE" bool="AND" name="My Saved Filter" target="Deleted Items">
      <condition attribute="TO" bool="AND" contains="CONTAINS">
         <value>rizwan@gwu.edu</value>
         <value>rizwan@seas.gwu.edu</value>
         <value>rizwans@bigfoot.com</value>
         <value>rizwan@rcn.com</value>
         <value>rizwansattar@hotmail.com</value>
      </condition>
   </filter>
</filterRoot>
I am trying to extract the <filter> element out and store it into a Vector of Elements (called, not surprisingly, filters). However, I am getting a class cast exception:
java.lang.ClassCastException: org.apache.xerces.dom.DeferredTextImpl
It is being called from where I trying to extract the <filter> in this way:
        filterRoot = doc.getDocumentElement(); // get topmost element
        NodeList list = filterRoot.getChildNodes();
        Vector newFilters = new Vector();
        debug("There are "+list.getLength()+" filters in document");
        for(int i=0; i<list.getLength(); i++) {
            Node n = list.item(i);
            debug("Node "+i+" getNodeValue() is "+n.getNodeValue());

            Element temp = (Element)n;
            newFilters.add(temp);
        }
Perhaps my question is, how do I correctly get hold of the <filter> node so that I may cast it as an Element?

thanks,
Riz
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 27 2006
Added on Mar 4 2002
6 comments
578 views