Schema type names aren't schema element names, just like Java class names
aren't field names.
Sometimes the element name is taken from the Java class name, and this is
not affected by @XmlType. If you have annotated Java classes (not generated
from a schema), and Bar is supposed to be marshalled as the outermost
element, an XmlRootElement( name="foo" ) should give you what you want.
Otherwise its the field name of the Bar field (or its annotation
XmlElement/XmlAttribute) that determines the element name.
For marshalling, there is also the option of constructing a JAXBElement
programmatically, which gives you control over the tag.
-W
On Mon, Jul 27, 2009 at 6:20 PM, Joe Kutner <jpkutner_at_gmail.com> wrote:
> I am having difficult understanding the expected behavior of the
> @XmlType attribute as described here:
>
> https://jaxb.dev.java.net/guide/Evolving_annotated_classes.html#Changing_class_names
>
> If I have a class such as:
>
> @XmlType(name = "foo")
> class Bar {}
>
> Should it not marshal to the following XML?
>
> <foo />
>
> I am not able to get this to work. I always get <bar/>.
>
> Thanks!
>
> Joe
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>