wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Need @XMLAttribute with name value even if variable name is same Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Need @XMLAttribute with name value even if variable name is same" Watch "Need @XMLAttribute with name value even if variable name is same" New topic
Author

Need @XMLAttribute with name value even if variable name is same

Premaa Kumar
Greenhorn

Joined: Sep 13, 2012
Posts: 2
please help me out here.
my xsd (only attribute portion not complete)

<xs:element name="E1">
<xs:complextype>
<xs:attribute name="xyz" type="xs:string" />
<xs:attribute name="xyz_abc" type="xs:string" />
</xs:complextype>
</xs:element>

produces JAXB class as (again not complete)

@XmlAttribute
protected String xyz;

@XmlAttribute(name="xyz_abc")
protected String xyzAbc;


but I want the JAXB file to be generated as

@XmlAttribute(name="xyz")
protected String xyz;

@XmlAttribute(name="xyz_abc")
protected String xyzAbc;

What change I have to make in xsd to generate the desired JAXB class.
I m using maven to generate the JAXB classes.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 520
    
    3
@XmlAttribute
protected String xyz;

That looks more likely an annotation by hand in object to xml mapping or an annotation generated via any other schema compilation (I have no idea which) tools other than via xjc bundled in the jaxb2 package. By its own, the meaning in practice would be quite the same. I could imagine one would have a hard time in fact to product that exact annotation without name = 'xyz' via xjc.

In any case, you can experiment with an external customisation file to re-iterate the should-be default naming... according the javebean property name.

But that seems a priori quite unnecessary, though.
 
GeeCON Prague 2014
 
subject: Need @XMLAttribute with name value even if variable name is same