Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i set value of a Jaxb XMLelement?

Tags:

jaxb

my question is: from the xml scheme :

<topnode>
    topNodeValue
   <bottomnode/> 
</topnode>

generated class with Jaxb looks like

class topnode {
    List<bottomnode> bottomnodeList;
}

Which does not generate the value field to set value for topnode.

How can I acheive this? Thanks.

like image 791
Tammy Avatar asked Jan 21 '26 07:01

Tammy


1 Answers

When the contents of an element contain both character and element data it is called mixed content. In JAXB (JSR-222) this is mapped with the @XmlMixed annotation like:

class topnode {
    @XmlMixed
    String text;

    List<bottomnode> bottomnodeList;
}

The use of mixed content can be tricky, since you may get unexpected results due to text nodes used for formatting. For a more detailed explanation see the following answer to a similar question.

  • https://stackoverflow.com/a/11099303/383861
like image 183
bdoughan Avatar answered Jan 25 '26 16:01

bdoughan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!