[XML]
I have already posted a message "Mapping a List at root returns
AnyNode objects instead of desired mapped object" and tried another
tack only to be thwarted again unfortunately so I'm clearly doing
something quite daft.
I need to unmarshall a list of simple objects and this time I have
created a wrapper java class to hold the list. But I can't seem to
get the mapping right. (Hopefully it's a mistake that will help
another beginner at least)
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 are my java classes:
public class PublistsSearchPubsResponse
{
private List pubs;
public List getPublicationList()
{
return pubs;
}
public void setPublicationList(List pubsList)
{
this.pubs = pubsList;
}
}
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):
<mapping>
<class name="qmul.qmrae.domain.SearchPubsResponse">
<map-to xml="search-publications-response" />
<field name="publicationList"
type="qmul.qmrae.domain.OutputImage" collection="collection"
container="false">
<bind-xml name="publication" />
</field>
</class>
<class name="qmul.qmrae.domain.OutputImage">
<field name="articleId">
<bind-xml name="id" node="attribute" />
</field>
</class>
</mapping>
And here is the unmarshalling java:
Unmarshaller unmarshaller = new Unmarshaller();
Mapping map = new Mapping();
map.loadMapping(getClass().getResource( "/castor-mapping-pubs.xml"
));
unmarshaller.setMapping(map);
List pubs = (ArrayList)
unmarshaller.unmarshal(fileReaderForMyXML);
But In the logs I see the following when it gets to the unmarshalling
step: org.exolab.castor.xml.UnmarshalHandler - unable to find
FieldDescriptor for 'publication' in ClassDescriptor of
search-publications-response - ignoring extra element.
And nothing is returned in the List
I expect what's causing this is at the root of my other problem but I
just can't seem to unpick this. I've been following this example
(http://castor.org/xml-mapping.html#4.-Usage-Pattern) and it looks the
same to me :-s
Hope you can help,
Rachel
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email