users@jaxb.java.net

Re: _at_XmlElementWrapper - question regarding naming the child elements

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 13 Nov 2009 06:59:34 +0100

Both annotations should precede the List<?> element, see

https://jaxb.dev.java.net/tutorial/section_6_2_7_7-Wrapping-Repeated-Elements-XmlElementWrapper.html#Wrapping%20Repeated%20Elements:%20XmlElementWrapper

-W

On Fri, Nov 13, 2009 at 1:17 AM, Alex Bleasdale <rhodlite78_at_yahoo.co.uk>wrote:

>
> Hi,
>
> Hoping someone can help. I'm using JAXB to generate XML based on some
> webservices I'm writing using Jersey. I have a Result bean, which
> generates
> a wrapper called "hits" and then proceeds to write out XML elements for
> each
> of the items in the list; which is great.
>
> However, the issue I'm having is each child element contains the same name
> as the wrapper, like this:
>
> <results>
> <hits>
> <hits id="12345" count="39"/>
> </hits>
> </results>
>
> I'd really like all of the items to have the name "hit" instead, like so:
>
> <hits>
> <hit id="12345" count="39"/>
> </hits>
>
> I was really hoping I could specify the name of the "root element" at the
> top of the child class (in this case TrackerHit), so the result bean has a
> section that looks like this:
>
> @XmlElementWrapper(name = "hits")
> public List<TrackerHit> getHits() {
> return hits;
> }
>
> And here's what I've got for the TrackerHit
>
> @XmlRootElement(name = "hit")
> public class TrackerHit {
> (...)
> }
>
> Anyone know how I can "label" child elements in a situation like this?
>
> Thanks in advance,
> Alex
> --
> View this message in context:
> http://old.nabble.com/%40XmlElementWrapper---question-regarding-naming-the-child-elements-tp26328516p26328516.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>