WSDL Tutorials - Herong's Tutorial Examples - Version 2.03, by Dr. Herong Yang
Creating a Data Object for Nested XML Elements
This section provides a tutorial example on how to create a SOAP::Data object to represent nested XML elements with one or more sub elements. The parent element's value should be the reference of an extra container object.
If you want to create a SOAP::Data object to represent nest XML elements - an XML element with one or more sub elements, you need to remember more rules:
Here is an example of using SOAP::Data to create nested XML element:
#- SOAP_Data_Nested_Elements.pl #- Copyright (c) 2009 by Dr. Herong Yang, herongyang.com #- All rights reserved # use SOAP::Lite; #- Creating data objects for sub elements $guest1 = SOAP::Data->new(name=>'Guest', value=>'Herong Yang'); $guest2 = SOAP::Data->name('Guest')->value('Joe Smith'); #- Creating the container object for the sub element list $list = SOAP::Data->new(); $list->value($guest1, $guest2); #- Creating the parent element $element = SOAP::Data->new(); $element->name('RegistrationRequest'); $element->uri('http://www.herongyang.com/Service/'); $element->prefix('hy'); $element->attr({'event'=>'OpenGame', 'date'=>'2008-08-08'}); $element->value(\$list); #- Dumping the element as an XML string $serializer = SOAP::Serializer->new(); $serializer->readable('true'); $xml = $serializer->serialize($element); print $xml;
Execution result of SOAP_Data_Nested_Elements.pl:
<?xml version="1.0" encoding="UTF-8"?> <hy:RegistrationRequest xmlns:hy="http://www.herongyang.com/Service/" date="2008-08-08" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" event="OpenGame" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Guest xsi:type="xsd:string">Herong Yang</Guest> <Guest xsi:type="xsd:string">Joe Smith</Guest> </hy:RegistrationRequest>
Conclusion, adding a sub element requires the reference of an extra container object.
Last update: 2009.
Table of Contents
WSDL 2.0 Document Structure and Syntax
WSDL Version 2.0 Part 2: Adjuncts
WSDL 2.0 Document Examples with SOAP Binding
WSDL 20 Programming APIs and Testing Tools
WSDL 1.1 Document Structure and Syntax
WSDL 1.1 Binding Extension for SOAP 1.1
soapUI 3.0.1 - Web Service Testing Tool
WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles
PHP SOAP Extension in PHP 5.3.1
►Using WSDL in Perl with SOAP::Lite 0.710
Introduction of Perl SOAP::Lite 0.710 for WSDL
Methods on SOAP::Lite 0.710 Client Object
Calling PRC Methods Defined in WSDL 1.1 Documents
service() Method Returns New Objects
SOAP::Data - XML Elements as Data Objects
SOAP::Serializer - Converting Data Objects to XML
Creating a Data Object for a Single XML Element
►Creating a Data Object for Nested XML Elements
SOAP::Deserializer - Converting XML to Data Objects
Calling XML Document Based Web Service
Using Operation Name as the SOAP Body Element Name
Using WSDL Document in Java with Axis2 1.4.1
Using WSDL2Java to Generate Web Service Stub Classes
WSDL 1.1 Binding Extension for SOAP 1.2
WSDL 1.1 and SOAP 1.2 Examples - Document and RPC Styles