[XML]

I need to unmarshall a list of simple objects.  I'd like iterate
through them without having to create a wrapper java class merely to
hold the list of objects in which I'm interested.

Very similar to this poster:
http://www.mail-archive.com/[email protected]/msg02830.html

And working almost exactly like this example:
http://www.castor.org/how-to-map-a-list-at-root.html


However after the unmarshalling step when I try and loop through what
I would expect to be PublicationImage objects in an ArrayList but
instead I'm getting org.exolab.castor.types.AnyNode objects and
therefore fails with a ClassCastException.

I've tried all sorts of variations using location attributes in the
mapping file or trying to map-to different nodes but it always falls
over at the same step for the same reason.  Here is a simplified
version of what I have at the moment...





Here is the XML I'd like to unmarshall:

    <search-publications-response item-count="2">
       <publication id="abc" />
       <publication id="def" />
    </search-publications-response>

Here is my class:


    public class PublicationImage
    {
        private String articleId;

        public String getArticleId()
        {
            return articleId;
        }

        public void setArticleId(String articleId)
        {
            this.articleId = articleId;
        }    
    }


here is my mapping file (castor-mapping-pubs.xml)

    <!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version
1.0//EN" 
    "http://castor.exolab.org/mapping.dtd";>
    <mapping>

      <class name="qmul.qmrae.domain.PublicationImage"
auto-complete="true">
        <map-to xml="search-publications-response"/>
        <field name="articleId">
            <bind-xml name="id" node="attribute" />
        </field>
      </class>

    </mapping>


And here is the unmarshalling java

    Unmarshaller unmarshaller = new Unmarshaller(ArrayList.class);

    Mapping map = new Mapping();
    map.loadMapping(getClass().getResource( "/castor-mapping-pubs.xml"
));
    unmarshaller.setMapping(map);

    List pubs = (ArrayList)
unmarshaller.unmarshal(fileReaderForMyXML);

    Iterator pubsIt = pubs.iterator();
    while (pubsIt.hasNext())
    {
        // this step is failing with a ClassCastException   
        PublistsOutputImage pub = (PublistsOutputImage) pubsIt.next();
    }



I'm using version 1.3 of the jars

I cannot change the XML structure that i'm unmarshalling because it is
a response from a third party API.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to