how to add namespace Prefix to all the elements of JAX-WS webservice output
This post will explain, how to add namespace Prefix to all the elements of JAX-WS webservice outputSometimes we may required to have the namespace prefix (ex.ns1) defined for all the elments of the JAX-WS webservice output.
The default annotation of the package-info.java class looks like below
@javax.xml.bind.annotation.XmlSchema(namespace = "PPDS:OPIRequest", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.reuters.eai.types;
This case only the parent element will be have the namespace prefix but not the child elements.
eg.
<ns1:Employee ns1="PPDS:OPIRequest">
<name></name>
<number></number>
</ns1:Employee>
To have the namespace prefix in all the output elements,modify the above annotaion in the package-info.java class as mentioned below.
@XmlSchema( namespace = "PPDS:OPIRequest", elementFormDefault = XmlNsForm.QUALIFIED, xmlns={@XmlNs(prefix="ns3", namespaceURI="PPDS:OPIRequest")})
package com.reuters.eai.types;
import javax.xml.bind.annotation.*;
e.g
<ns1:Employee ns1="PPDS:OPIRequest">
<ns1:name></ns1:name>
<ns1:number></ns1:number>
</ns1:Employee>
How do you change the prefix of a different package, aka namespace?
ReplyDeleteCreate a package-info.java file in the package and specifiy the package name and the namespace accordingly.
ReplyDelete@javax.xml.bind.annotation.XmlSchema(namespace = "PPDS:OPIRequest", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.reuters.eai.types;
Regards
Albin I
The soap xml did not post to the comment, thinks it html I guess
ReplyDeletens3:yearlyReturnsAsOfDate
ReplyDeletedayOfMonth>30/dayOfMonth
month>6/month
year>2014/year