If you just need to specify a namespace, then there are two options.
The first is to indicate in the annotation:
@XmlRootElement(name = "DCTRequest", namespace = "http://***.com")
The second is to create a package-info.java file in the same package with the following contents:
@javax.xml.bind.annotation.XmlSchema(namespace = "http://***.com", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package your.package.name;
In both cases, the output will be:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <DCTRequest xmlns="http://***.com"> ... </DCTRequest>
If it is necessary that the prefix name be "p", then we modify package-info.java in the second version:
@XmlSchema(namespace = "http://***.com", xmlns = @XmlNs(prefix = "p", namespaceURI = "http://***.com"), elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package your.package.name; import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlSchema;
the output will be:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <p:DCTRequest xmlns:p="http://***.com"> ... </p:DCTRequest>
If you need several prefixes, you can write this:
@XmlSchema(namespace = "http://***.com", xmlns = { @XmlNs(prefix = "p", namespaceURI = "http://***.com"), @XmlNs(prefix = "p1", namespaceURI = "www.**.com/datatypes"), @XmlNs(prefix = "p2", namespaceURI = "www.**.com/DCTRequestdatatypes") }, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package test.aaa; import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlSchema;
and just the elements indicate the namespace, and the prefixes themselves are substituted.