SOAP Code Example: Using Complex Types
C#
soap.Method = "test";
soap.MethodURI = "http://tempuri.org";
soap.ValueFormat = SoapValueFormats.vfFullXML;
soap.AddParam("parent", "
Java
soap.setMethod("test");
soap.setMethodURI("http://tempuri.org");
soap.setValueFormat(soap.vfFullXML);
soap.addParam("parent", "
will result in a SOAPPacket which looks like:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:="">
<SOAP-ENV:Body>
<m:test xmlns:m="http://tempuri.org">
<parent>
<child1>
<grandchild1>test</grandchild1>
</child1>
</parent>
</m:test>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
If the server returns a complex type in response to your request you can use the XPath and related properties to traverse the response. For instance if the server returned the value:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:="">
<SOAP-ENV:Body>
<m:TestResults xmlns:m="http://tempuri.org">
<parent>
<child1>
<grandchild1>value1</grandchild1>
<grandchild2>value2</grandchild2>
</child1>
</parent>
</m:TestResults>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
You could use the code below to output the value for the grandchild2 element. Please consult the help files for a complete list of XPath related properties that may be useful in your application.
C#
soap.XPath = "/Envelope/Body/TestResults/parent/child1/grandchild2";
Console.WriteLine(soap.XText);
Java
soap.setXPath("/Envelope/Body/TestResults/parent/child1/grandchild2");
System.out.println(soap.getXText());
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.