Beginner needs help with sending/receiving XML data


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="" xmlns:tns=""
xmlns:xsd="" xmlns:soap=""
targetNamespace="" name="EPAService">
<xsd:import schemaLocation="" namespace="" />
<message name="SendSpecific">
<part element="tns:SendSpecific" name="parameters" />
<message name="SendSpecificResponse">
<part element="tns:SendSpecificResponse" name="parameters" />
<portType name="EPAService">
<operation name="SendSpecific">
<input message="tns:SendSpecific" />
<output message="tns:SendSpecificResponse" />
<binding name="EPAServicePortBinding" type="tns:EPAService">
<soap:binding style="document" transport="" />
<operation name="SendSpecific">
<soap:operation soapAction="" />
<soap:body use="literal" />
<soap:body use="literal" />
<service name="EPAService">
<port name="EPAServicePort" binding="tns:EPAServicePortBinding">
<soap:address location="" />

this is the second:

<?xml version+"1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="" targetnameSpace="" version="1.0">
<xs:element xmlns:ns1="" name="SendSpecific" type="ns1:SendSpecific" />
<xs:complexType name="SendSpecific">
<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:element xmlns:ns2="" name="SendSpecificResponse" type="ns2:SendSpecificResponse" />
<xs:complexType name="SendSpecificResponse">
<xs:element name="return" type="xs:string" minOccurs="0" />

and this is the truncated ‘example xml’:

<Name>Mr J Bloggs</Name>
<Addr1>22 Acacia Avenue</Addr1>
<Pcode>AB1 1BA</Pcode>

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

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

After you get through that, try these SOAP articles (also a bit old) and maybe (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:

    $client=new soapclient($wsdl, 'wsdl');
        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?


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