Reputation: 113
How can I remove or rename 'ns2' prefix here:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:GetCatalogResponse xmlns:ns2="https://domain.com/">
<GetCatalogResult>result</GetCatalogResult>
</ns2:GetCatalogResponse>
</S:Body>
</S:Envelope>
package-info.java:
@XmlSchema(
namespace = "https://domain.com/",
xmlns = {
@XmlNs(prefix = "xxx", namespaceURI="https://domain.com/")
},
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED
)
package com.domain.xxx;
Result:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:GetCatalogResponse xmlns:ns2="https://domain.com/">
<GetCatalogResult>result</GetCatalogResult>
</ns2:GetCatalogResponse>
</S:Body>
</S:Envelope>
By docs @XmlNs should override default prefix for xml items. But in my case it doesnt work.
Why?
Upvotes: 3
Views: 5307
Reputation: 113
Prefix can be modified by SOAPHandler
like this
SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
SOAPBody body = envelope.getBody();
Iterator iter = body.getChildElements();
while (iter.hasNext()) {
Object object = iter.next();
if (object instanceof SOAPElement) {
SOAPElement element = (SOAPElement) object;
element.removeNamespaceDeclaration(element.getPrefix());
element.setPrefix("");
}
}
Upvotes: 2