Java – JAXB: how to annotate classes to belong to different namespaces?
•
Java
I want classes with JAXB annotations
What I need is:
What should I do?
Is it programmable? (JAXB. XJB binding file is not required?)
Solution
@H_ 502_ 5@@XmlRootElement(name="someRootElement",namespace = "urn:my:ns1") class Test { @XmlElement(name="someElement",namespace="urn:my:ns1") String elem1 = "One"; @XmlElement(name="someElement",namespace="urn:my:ns2") String elem2 = "Two"; @XmlElement(name="someElement",namespace="urn:my:ns3") String elem3 = "Three"; }
This will be encoded into the following XML:
If you use JAXB RI and don't like the default NS2 and NS3 namespace prefixes, you need to provide your own namespaceprefixmapper
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码