Beginner needs help with sending/receiving XML data

Hi,

I’ve recently completed a quote system for a client, using PHP and MySQL. The system works fine, but the client now wants to import the captured data into their in-house server which accepts XML data.

I’ve never worked with XML but thought that this would be a simple task of calling an XML template during the quote process, populating it with the data variables and using some sort of PHP script to send the file to the server.

However, they have provided me with the XML structure and now I’m more confused than ever! This is the first file:


<?xml version="1.0" encoding="UTF-8" ?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="www.shlquotes.co.uk"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="www.xxx999.co.uk" name="EPAService">
<types>
<xsd:schema>
<xsd:import schemaLocation="http://1.1.1.1:80/EPAService/EPAService?xsd=1" namespace="www.xxx999.co.uk" />
</xsd:schema>
</types>
<message name="SendSpecific">
<part element="tns:SendSpecific" name="parameters" />
</message>
<message name="SendSpecificResponse">
<part element="tns:SendSpecificResponse" name="parameters" />
</message>
<portType name="EPAService">
<operation name="SendSpecific">
<input message="tns:SendSpecific" />
<output message="tns:SendSpecificResponse" />
</operation>
</portType>
<binding name="EPAServicePortBinding" type="tns:EPAService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="SendSpecific">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="EPAService">
<port name="EPAServicePort" binding="tns:EPAServicePortBinding">
<soap:address location="http://1.1.1.1:80/EPAService/EPAService" />
</port>
</service>
</definitions>

this is the second:


<?xml version+"1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetnameSpace="www.xxx999.co.uk" version="1.0">
<xs:element xmlns:ns1="www.xxx999.co.uk" name="SendSpecific" type="ns1:SendSpecific" />
<xs:complexType name="SendSpecific">
<xs:sequence>
<xs:element name="triposIPAddressOrHost" type="xs:string" minOccurs="0" />
<xs:element name="portNumber" type="xs:short" />
<xs:element name="timeOutSetting" type="xs:short" />
<xs:element name="branchNumber" type="xs:short" />
<xs:element name="xmlInput" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:element xmlns:ns2="www.xxx999.co.uk" name="SendSpecificResponse" type="ns2:SendSpecificResponse" />
<xs:complexType name="SendSpecificResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:schema>

and this is the truncated ‘example xml’:


<APMIMPORT>
<APMCLIENT>
<P.CM>
<Refno>12345</Refno>
<Name>Mr J Bloggs</Name>
<Addr1>22 Acacia Avenue</Addr1>
<Addr2>Somewhere</Addr2>
<Addr3>Anytown</Addr3>
<Pcode>AB1 1BA</Pcode>
</P.CM>
</APMCLIENT>
</APMIMPORT>

I am assuming that the first file sends the data and the second receives the response using a PHP (or similar) script? I am also assuming that the schemaLocation needs to be amended to the IP address of the server the data is to sent to, and that the namespace should be the url of the page receiving the response.

Firstly, are my assumptions correct? Secondly, how do I insert the XML data? Is it appended to the first file or sent as a separate file altogether?

No doubt I’ll have many more questions but I would be eternally grateful for any help with this.

Thanks in advance.

This is a “subset” of XML - WSDL (Web Services Description Language).
The first file is the WSDL document which describes the web service.
The second is the schema which describes the structure of the XML file.
The third of course is an example XML file.

Namespaces are not URLs (location), but rather URIs (identifiers).
Although by convention they look similar, URIs do not have to be URLs.

This may help some http://www.w3schools.com/WSDL/wsdl_intro.asp

Thanks for that, the link was helpful.

So let’s say I reach the stage in the application where I need to send the XML data. Do I need to implement a script to a) write the necessary variables into the xml file b) open the WSDL document c) open the schema document, and d) send all three documents to correct IP address?

The data is transported using SOAP. SOAP (to me at least) is similar to, but more complex than XML-RPC. This old SitePoint article should still prove to be helpful http://www.sitepoint.com/article/own-web-service-php-xml-rpc/

After you get through that, try these SOAP articles http://www.onlamp.com/pub/a/php/2003/07/03/php_amazon_soap.html (also a bit old) and maybe http://www.sitepoint.com/article/track-rank-google-api/ (if you have a Google developer key)

Thanks for responding - I think I’m almost there now.

I think the PHP script I’m using to transport the data is working OK, but I’m getting no response from the server. Here is the script I’m using:



<?php
require_once('../lib/nusoap.php');
$wsdl="http://xx.xxx.xxx.xxx:xxxxx/EPAService/EPAService?wsdl";
try
{
    $client=new soapclient($wsdl, 'wsdl');
    if($client->getError())
    {
        throw new Exception($client->getError());
    }
    $sXML = file_get_contents('write.xml');
    if( ! $sXML)
    {
        throw new Exception('Sorry, I cannot read the source XML.');
    }
    $response = $client->call('EPAService', $sXML);
    echo '<h2>Response:-</h2>';
    echo '<pre>';
    echo htmlentities($response);
    echo '</pre>';
}
catch(Exception $oException)
{
    echo $oException->getMessage();
}
?>

If you look at the WSDL file above, am I trying to call the correct service (EPAService)? Or have I got this totally wrong?

Anybody?

Hard to test, since we don’t see which host it is going against.