1

i'm trying to create a soap request, i learn from https://stackoverflow.com/a/15949858/4799735 from thats tutorial, i get confused, how to create a xml like this

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

my workcode are

SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("GetUserInfo");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("type", "ArgComKey","xsd");
    SOAPBodyElement element = soapBody.addBodyElement(envelope.createName("type", "ArgComKey", "=xsd:integer"));
    soapBodyElem1.addTextNode("ComKey");
    SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("Arg");
    soapBodyElem2.addTextNode("123");

    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURI + "VerifyEmail");

it's return

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

my question is what i have to write so that my code result is

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

1 Answers1

2

You could try with this:

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" );

This will result with:

<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>

If you want to use xsi namespace you should try with this code:

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" );

Thanks to this you will receive:

<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>
Mateusz Sroka
  • 2,255
  • 2
  • 17
  • 19