Matt,
that would be something like:
@XmlRootElement(name="RESULT")
public class Result
{
@XmlElementWrapper(name="ERRORS") @XmlElement(name="ERROR") public List<Error> errors;
@XmlElementWrapper(name="WARNINGS") @XmlElement(name="WARNING") public List<Warning> warnings;
public static class Warning {
@XmlAttribute public String externalId;
@XmlAttribute public int rowId;
@XmlValue public String message;
}
}
Haven't tried it.
Matthias
BTW: the javadoc of XmlElementWrapper leaves something to be desired. Actually the annotation doesn't occur once in its own usage example !?
http://java.sun.com/javaee/5/docs/api/javax/xml/bind/annotation/XmlElementWrapper.html
-----Original Message-----
From: Matthew Huang [mailto:matthewhuang2004_at_gmail.com]
Sent: Thu 2/22/2007 21:41
To: users_at_jaxb.dev.java.net
Subject: how to unmarshall an xml file with attribute using annotation?
I got a xml file:
-----------------------------------------------------------
<RESULT>
<ERRORS>
</ERRORS>
<WARNINGS>
<WARNING externalId="A1" rowId="1">the warning message 1</WARNING>
<WARNING externalId="A2" rowId="1">the warning message 2</WARNING>
<WARNING externalId="A3" rowId="1">the warning message 3</WARNING>
<WARNINGS>
<RESULT>
-----------------------------------------------------------
How do I code my Java Beans with annotation (e.g. @XmlElement) to do
unmarshalling (and latter marshalling)?
Another question is that the warning message can only be decided at runtime.
So basically I need to map warnings to be a java collection, sth like
List<warning>, how do I do this?