WSDL Tutorials - Herong's Tutorial Examples - Version 2.03, by Dr. Herong Yang
SOAP::Deserializer - Converting XML to Data Objects
This section provides a tutorial example on how to convert XML strings into SOAP::Data objects in 2 steps: call serialize() method from SOAP::Deserializer class, then call dataof() method from SOAP::SOM class.
Now I know how to create SOAP::Data objects to represent different types of XML elements. I also know how to convert a SOAP::Data object into an XML string. The next question is how to convert an XML string back to a SOAP::Data object.
SOAP::Lite 0.710 manual does not mentioning how to convert, deserialize, XML strings into SOAP::Data objects anywhere. But I found this undocumented method, deserialize(), on the SOAP::Deserializer that will do the job. There are two steps to deserialize XML strings into SOAP::Data objects:
1. Using the serialize() class/object method in the SOAP::Deserializer class to convert an XML string into a SOAP::SOM object:
$som = SOAP::Deserializer->deserialize($xml);
2. Using the dataof() object method in the SOAP::SOM class to convert the root element or a sub element of SOAP::SOM into a SOAP::Data object:
$data = $som->dataof(xpath);
where 'xpath' is a XPATH expression referring to the root element or a sub element.
Here is an example Perl program that shows you how to convert a SOAP::Data object into an XML string:
#- SOAP_Data_from_XML_String.pl #- Copyright (c) 2009 by Dr. Herong Yang, herongyang.com #- All rights reserved # use SOAP::Lite; $xml = <<END_XML; <hy:RegistrationRequest xmlns:hy="http://www.herongyang.com/Service/" date="2008-08-08" event="OpenGame" > <Guest>Herong Yang</Guest> <Guest>Joe Smith</Guest> </hy:RegistrationRequest> END_XML #- Converting XML to a SOAP::SOM object $deserializer = SOAP::Deserializer->new(); my $som = $deserializer->deserialize($xml); #- Converting a SOAP::SOM object to a SOAP::Data object $data = $som->dataof('//'); #- Checking the SOAP::Data object print "name: ".$data->name()."\n"; print "namespace: ".$data->uri()."\n"; print "prefix: ".$data->prefix()."\n"; print "attributes: ".$data->attr()."\n"; print "value: ".$data->value()."\n";
Execution result of SOAP_Data_from_XML_String.pl:
name: RegistrationRequest namespace: http://www.herongyang.com/Service/ prefix: hy attributes: HASH(0x1bf5860) value: HASH(0x1c07108)
Notes on the program and the result:
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