issue while converting xsd to java pojo when attribute name="value" -
how can convert below piece of xsd java pojo. tried using jaxb project way using eclipse convert giving me error( property "value" defined. use <jaxb:property> resolve conflict.). think because have name="value" , conflicting somewhere.
<xs:complextype name="demo"> <xs:simplecontent> <xs:extension base="xs:string"> <xs:attribute name="value" type="xs:string" /> </xs:extension> </xs:simplecontent> </xs:complextype> help appreciated!
the java class representing complex type might this:
@xmltype(name = "demo") public class demo { private string valueattr; private string valuecontent; @xmlattribute(name = "value") public string getvalueattr() { return this.valueattr; } public void setvalueattr(string valueattr) { this.valueattr = valueattr; } @xmlvalue public string getvaluecontent() { return this.valuecontent; } public void setvaluecontent(string valuecontent) { this.valuecontent = valuecontent; } } class name, fields names, , method names can changed whatever want them be, since xml names explicitly given in annotations.
to see working, use this:
@xmlrootelement public class test { @xmlelement private demo demo; public static void main(string[] args) throws exception { demo demo = new demo(); demo.setvalueattr("this attr value"); demo.setvaluecontent("this element content"); test test = new test(); test.demo = demo; jaxbcontext jaxbcontext = jaxbcontext.newinstance(test.class); marshaller marshaller = jaxbcontext.createmarshaller(); marshaller.setproperty(marshaller.jaxb_formatted_output, boolean.true); marshaller.marshal(test, system.out); } } output
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <test> <demo value="this attr value">this element content</demo> </test>
Comments
Post a Comment