users@jaxb.java.net

RE: how to unmarshall an xml file with attribute using annotation?

From: Matthew Huang <matthewhuang2004_at_gmail.com>
Date: Fri, 23 Feb 2007 07:18:31 -0800 (PST)

Thanks, Matthias, I've tried it and it works great!.

The Javadoc is not clear but this annotation is really helpful since I wanna
make some dynamic mapping at the runtime.

Matthew


Ernst, Matthias wrote:
>
> 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?
>
>

-- 
View this message in context: http://www.nabble.com/how-to-unmarshall-an-xml-file-with-attribute-using-annotation--tf3275139.html#a9120484
Sent from the java.net - jaxb users mailing list archive at Nabble.com.