JavaSE soap定制

JavaSE soap定制,java,soap,Java,Soap,我试图创建一个soap请求,我从 从这篇教程中,我很困惑,如何创建这样的xml <GetUserInfo> <ArgComKey Xsi:type="xsd:integer"> ComKey </ ArgComKey> <Arg> <PIN Xsi:type="xsd:integer"> Job Number </ PIN> </ Arg> </ GetUserInfo> 回来了

我试图创建一个soap请求,我从 从这篇教程中,我很困惑,如何创建这样的xml

<GetUserInfo>
  <ArgComKey Xsi:type="xsd:integer"> ComKey </ ArgComKey> 
 <Arg> 
  <PIN Xsi:type="xsd:integer"> Job Number </ PIN> 
 </ Arg> 
</ GetUserInfo>
回来了

<GetUserInfo>
<ArgComKey:type xmlns:ArgComKey="xsd">ComKey</ArgComKey:type>
<Arg>123</Arg>
</GetUserInfo><ArgComKey:type xmlns:ArgComKey="=xsd:integer"/>

康基
123
我的问题是我必须写什么,这样我的代码结果才是正确的

<ArgComKey Xsi:type="xsd:integer"> ComKey </ ArgComKey>
ComKey

您可以尝试以下方法:

SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement( "GetUserInfo" );
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement( "ArgComKey", "", "xsd:integer" );
soapBodyElem1.addTextNode( "ComKey" );
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement( "Arg" );
soapBodyElem2.addTextNode( "123" );
这将导致:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header />
    <SOAP-ENV:Body>
        <GetUserInfo>
            <ArgComKey xmlns="xsd:integer">ComKey</ArgComKey>
            <Arg>123</Arg>
        </GetUserInfo>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
为此,您将收到:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Header />
    <SOAP-ENV:Body>
        <GetUserInfo>
            <ArgComKey xsi:type="xsd:integer">ComKey</ArgComKey>
            <Arg>123</Arg>
        </GetUserInfo>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

康基
123

谢谢aswer,但我需要将ComKey更改为ComKey
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("xsi","http://www.w3.org/2001/XMLSchema-instance");
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement( "GetUserInfo" );
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement( "ArgComKey" );
soapBodyElem1.addTextNode( "ComKey" ).setAttribute("xsi:type","xsd:integer");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement( "Arg" );
soapBodyElem2.addTextNode( "123" );
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Header />
    <SOAP-ENV:Body>
        <GetUserInfo>
            <ArgComKey xsi:type="xsd:integer">ComKey</ArgComKey>
            <Arg>123</Arg>
        </GetUserInfo>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>