Soap JAX-WS删除';ns';xml标记的前缀
如何在此处删除或重命名“ns2”前缀:Soap JAX-WS删除';ns';xml标记的前缀,soap,jax-ws,Soap,Jax Ws,如何在此处删除或重命名“ns2”前缀: <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:GetCatalogResponse xmlns:ns2="https://domain.com/"> <GetCatalogResult>result</GetCatalogResult> &
<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>
结果:
<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应覆盖xml项的默认前缀。但在我的情况下,它不起作用
为什么?前缀可以通过
SOAPHandler
这样修改
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("");
}
}
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("");
}
}