users@jaxb.java.net

Re: tag with attributes and text content as a field

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Sat, 12 Sep 2009 18:31:23 +0200

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "FooType", propOrder = {
    "content"
})
public class FooType {

    @XmlValue
    protected String content;
    @XmlAttribute
    protected String type;
    // ...
}

-W

On 9/12/09, Benjamin Reed <rangerrick_at_gmail.com> wrote:
> I could have sworn I've seen a way to do this before but I can't for
> the life of me find it. I'd like to output XML with JAXB in a
> particular format, ie:
>
> <foo type="bar">baz</foo>
>
> If my class looks like this:
>
> @XmlRootElement(name="foo")
> @XmlAccessorType(XmlAccessType.FIELD)
> public class Foo {
> @XmlAttribute
> String type;
> @XmlElement
> String value;
> }
>
> I end up with this XML:
>
> <foo type="bar">
> <value>baz</value>
> </foo>
>
> Does anyone know how to make the "value" field end up as the contents of
> foo?
>
> --
> Benjamin Reed a.k.a. Ranger Rick
> Fink, KDE, and Mac OS X development
>
> Blog: http://www.raccoonfink.com/
> Music: http://music.raccoonfink.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>