【问题标题】:SOAP - leave only parent/root namespaceSOAP - 只保留父/根命名空间
【发布时间】:2020-08-31 06:25:51
【问题描述】:

我有几个 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 必须被删除。 有什么方法可以实现吗?

【问题讨论】:

    标签: java spring soap jaxb


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-20
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 2012-03-28
      相关资源
      最近更新 更多