如何在不丢失注释的情况下解组和编组XML文件?有没有办法使用JAXB,我尝试使用以下link但它不起作用 .
<customer>
<address>
<!-- comments line 1 -->
<street>1 Billing Street</street>
</address>
<address>
<!-- comments line 2-->
<street>2 Shipping Road</street>
</address>
</customer>
我想解组上面的xml,为它添加一个新地址并对其进行编组,而不会丢失以下注释 .
<!-- comments line 1 -->
<!-- comments line 2-->
2 回答
也许更容易调整/扩展客户地址的(数据)模型 .
这样,语义在模型中不会在注释中“隐藏” .
您可以将JAXB与StAX结合使用以访问尾随注释 .