Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中为Soap元素添加正确的属性_Java_Soap - Fatal编程技术网

如何在java中为Soap元素添加正确的属性

如何在java中为Soap元素添加正确的属性,java,soap,Java,Soap,我想向soap元素添加属性,如 <SdcPDU xmlns="urn:sdcf:sdc:xsd:faa.2.0"> <Revision>2.0.2</Revision> </SdcPDU> 但输出消息看起来像 <SdcPDU xmlns=""> <Revision xmlns="urn:sdcf:sdc:xsd:faa.2.0">2.0.2</Revision> </SdcPDU> 2.0

我想向soap元素添加属性,如

<SdcPDU xmlns="urn:sdcf:sdc:xsd:faa.2.0">
<Revision>2.0.2</Revision>
</SdcPDU>
但输出消息看起来像

<SdcPDU xmlns="">
   <Revision xmlns="urn:sdcf:sdc:xsd:faa.2.0">2.0.2</Revision>
</SdcPDU>

2.0.2

谁能帮帮我

下面的代码应该会产生预期的结果

SOAPElement sdcPDU = soapBody.addChildElement("SdcPDU","","urn:sdcf:sdc:xsd:faa.2.0");
    SOAPElement revision = sdcPDU.addChildElement("Revision");
    revision.addTextNode("2.0.2");
答复:


2.0.2

在参考示例中,名称空间应用于SdcPDU。这将是应用于SdcPDU元素的子元素的默认名称空间。我不知道为什么名称空间会附加到子元素。但最终还是和你预期的结果一样。
SOAPElement sdcPDU = soapBody.addChildElement("SdcPDU","","urn:sdcf:sdc:xsd:faa.2.0");
    SOAPElement revision = sdcPDU.addChildElement("Revision");
    revision.addTextNode("2.0.2");
<SOAP-ENV:Body>
  <SdcPDU xmlns="urn:sdcf:sdc:xsd:faa.2.0">
      <Revision>2.0.2</Revision>
  </SdcPDU>
</SOAP-ENV:Body>