如何将空字符串封送到单个标记 [英] How to marshal empty string to a single tag
问题描述
我的对象,配置代码:
object.setName("");
编组成以下XML:
<object>
<name></name>
</object>
但我想要单个标签:
<object>
<name/>
</object>
一次对所有对象使用JAXB是否容易?
Is it easy to do with JAXB for all my objects at once?
更新
类似的问题:
如何使用JAXB实例化空元素
它是建议使用prettifier javax.xml.transform.TransformerFactory.newTransformer(),但没有解释如何使用它。理想情况下,我的目标是获取精确的代码来配置JAXB以获得所需的结果。
It's suggested to use prettifier javax.xml.transform.TransformerFactory.newTransformer(), but without explanation how to use it. Ideally my goal is to get exact code to configure JAXB to get the desired result.
谢谢。
推荐答案
在另一个问题中找到了我的问题的答案如何使用JAXB实例化一个空元素,建议使用一个美化器或根本不做任何事情,因为两个版本的XML都是等价的。
The answer to my question was found in another question How to instantiate an empty element with JAXB where it's suggested to either use a prettifier or don't do anything at all because both versions of XML are equivalent.
这篇关于如何将空字符串封送到单个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!