No, that is slightly different. That defines the namespace on the
*usage* of a class. I need it defined on the class itself, so I don't
have to repeat the annotation for every field and try to keep that
consistent.
I'm trying to resolve cases where I have two classes with the same
fully qualified name (and the same element name), but different
semantics. Using a namespace for the element would allow me to run
the XML doc through a stylesheet. Any suggestions?
On Tue, Jul 28, 2009 at 4:36 AM, Wolfgang Laun<wolfgang.laun_at_gmail.com> wrote:
> This should do what you want:
>
> class Village {
> ...
> @XmlElement( name = "maison", namespace = "French" )
> public House getHouse(){
> ...
> }
> ...
> }
>
> If Village is the top level element, the namespace is defined there, and the
> "house" element's tag just shows the prefix:
>
> <village xmlns:ns2="French">
> <ns2:maison>
> <name>...</name>
> </ns2:maison>
> </village>
>
> -W
>
>
> On Mon, Jul 27, 2009 at 10:39 PM, Joe Kutner <jpkutner_at_gmail.com> wrote:
>>
>> Ok, what I am really trying to do is apply a attribute to a class so
>> that it always marshals to an element with a particular namespace -
>> even if it is not the root element. Is there a way to do this? The
>> Simple-XML binding framework provides a @Namespace annotation for this
>> purpose. Is something like this available in JAXB?
>>
>> @Namespace(reference = "foo.bar")
>> class Foobar {}
>>
>> produces this when used as a field in MyRootClass:
>>
>> <myRootClass>
>> <foobar xmlns="foo.bar"/>
>> </myRootClass>
>>
>> Thanks again,
>>
>> Joe
>>
>>
>> On Mon, Jul 27, 2009 at 12:19 PM, Wolfgang Laun<wolfgang.laun_at_gmail.com>
>> wrote:
>> > 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
>> >>
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>
>