SOAP Code Example: Using Complex Types

To send a complex type you first need to set the ValueFormat property to tell the component to not xml escape the data you're providing. For instance:

C#
soap.Method = "test";
soap.MethodURI = "http://tempuri.org";
soap.ValueFormat = SoapValueFormats.vfFullXML;
soap.AddParam("parent", "test");
soap.BuildPacket();

Java
soap.setMethod("test");
soap.setMethodURI("http://tempuri.org");
soap.setValueFormat(soap.vfFullXML);
soap.addParam("parent", "test");
soap.buildPacket();

will result in a SOAPPacket which looks like:





	
		
			test
		
	



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:





	
		
			value1
			value2
		
	



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 kb@nsoftware.com.