SOAP – 只保留父/根命名空间

huangapple go评论66阅读模式
英文:

SOAP - leave only parent/root namespace

问题

我有几个用于创建SOAP消息组合的xsd文件。
问题是每当构建对象时,它会导入所有继承的xmlns。我没有找到关于这个问题的任何信息。有没有什么办法只保留根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>

需要删除S:Envelope中的xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"以及testRes中的xmlns:ns2="http://yyy/yyy/yyy/v1" xmlns:ns3="http://zzz/zzz/zzz/v1"。是否有方法可以实现这一点?

英文:

I have several xsd files which are used to create a composition of one SOAP message.
The problem is that whenever object is build it imports all inherited xmlns. I didn't found anything about this problem. Is there any way to leave only root xmlns?

Example:

&lt;S:Envelope xmlns:S=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
   &lt;S:Body&gt;
      &lt;testRes xmlns=&quot;http://xxx/xxx/xxx/v1&quot; xmlns:ns2=&quot;http://yyy/yyy/yyy/v1&quot; xmlns:ns3=&quot;http://zzz/zzz/zzz/v1&quot;&gt;
         &lt;status&gt;B&lt;/status&gt;
         &lt;opisBledu&gt;Error msg...&lt;/opisBledu&gt;
      &lt;/testRes&gt;
   &lt;/S:Body&gt;
&lt;/S:Envelope&gt;

I need the message to be:

&lt;S:Envelope xmlns:S=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
   &lt;S:Body&gt;
      &lt;testRes xmlns=&quot;http://xxx/xxx/xxx/v1&quot;
         &lt;status&gt;B&lt;/status&gt;
         &lt;opisBledu&gt;Error msg...&lt;/opisBledu&gt;
      &lt;/testRes&gt;
   &lt;/S:Body&gt;
&lt;/S:Envelope&gt;

There is need that
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" from S:Envelope
and xmlns:ns2="http://yyy/yyy/yyy/v1" xmlns:ns3="http://zzz/zzz/zzz/v1" from testRes has to be removed.
Is there any way to achieve this?

答案1

得分: 1

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

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

根据您的情况,需要删除不必要的定义。

英文:

Yes, you can specify xmlns inside annotations @XmlRootElement @XmlElement @XmlType in your classes or inside package-info.java.
For example:

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

In your case need to remove unnecessary definitions

huangapple
  • 本文由 发表于 2020年8月31日 14:25:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63665809.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定