SOAP - 仅保留 parent/root 命名空间

SOAP - leave only parent/root namespace

我有几个 xsd 文件,用于创建一个 SOAP 消息的组合。 问题是无论何时构建对象,它都会导入所有继承的 xmlns。我没有发现任何关于这个问题的信息。有没有办法只留下root xmlns?

示例:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <testRes xmlns="http://xxx/xxx/xxx/v1" xmlns:ns2="http://yyy/yyy/yyy/v1" xmlns:ns3="http://zzz/zzz/zzz/v1">
         <status>B</status>
         <opisBledu>Error msg...</opisBledu>
      </testRes>
   </S:Body>
</S:Envelope>

我需要的消息是:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <testRes xmlns="http://xxx/xxx/xxx/v1"
         <status>B</status>
         <opisBledu>Error msg...</opisBledu>
      </testRes>
   </S:Body>
</S:Envelope>

有需要 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 来自 S:Envelope 并且 xmlns:ns2="http://yyy/yyy/yyy/v1" xmlns:ns3="http://zzz/zzz/zzz/v1" 来自 testRes 必须删除。 有什么办法可以实现吗?

是的,您可以在 类 或 package-info.java 中的注释 @XmlRootElement @XmlElement @XmlType 中指定 xmlns。 例如:

@XmlRootElement (name = "testRes", namespace = "http://xxx/xxx/xxx/v1")
public class TestRes 

在你的情况下需要删除不必要的定义