How to create an XML text node with an empty string value (in Java)

后端 未结 7 1694
温柔的废话
温柔的废话 2020-12-16 16:00

I am using a Transform object to save my XML file but it seems to drop empty text nodes. Is there any way to create (and keep) a text node with an empty string

7条回答
  •  萌比男神i
    2020-12-16 16:59

    You should anotate your field with

    @XmlElement(nillable=true)
    

    Just set it to null and you will get:

    
    

    It indicates that an element is empty.

    Otherwise, if you want just open and close tags, just set its value to "" (empty String). And you will get:

    
    

提交回复
热议问题