0

I can create an XML element in Java by using the annotation javax.xml.bind.annotation.XmlElement

@XmlElement(name="foo")

that produces the following XML element

<foo/>

Now, I want to create the following tag:

<foo attr="attrval"/>

How can I do that by using annotations?

mat_boy
  • 12,998
  • 22
  • 72
  • 116
  • Have you tried [@XmlAttribute](http://docs.oracle.com/javaee/7/api/javax/xml/bind/annotation/XmlAttribute.html) annotation? – Dmitry Kuskov Sep 25 '13 at 08:00
  • Yes, it creates an attribute for the `@XmlRootNode`. It doesn't create a new empty element with an attribute. I know, I can create a new class FOO with the attribute `@XmlAttribute` and then create an object FOO annotated with the `@XmlElement`, but it looks a lot verbose to me. – mat_boy Sep 25 '13 at 08:03
  • You can use this:[link]http://stackoverflow.com/questions/3666467/how-can-i-add-xml-attributes-to-jaxb-annotated-class-xmlelementwrapper – Wenod Pathirana Sep 25 '13 at 08:07
  • @WenodPathirana It is exactly what I said! I have to create a class that embeds the annotation for the attribute. Nothing less verbose? – mat_boy Sep 25 '13 at 08:11

0 Answers0