How to add an XML namespace (xmlns) when serializing an object to XML
问题 I'm serializing Objects to XML with the help of XStream. How do I tell XStream to insert an xmlns to the XML output of my object? As an example, I have this simple object I want to serialize: @XStreamAlias(value="domain") public class Domain { @XStreamAsAttribute private String type; private String os; (...) } How do I achieve exactly the following output with XStream? <domain type="kvm" xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> <os>linux</os> </domain> 回答1: Alternatively, this