0

I am working with an API at the moment, that accepts XML in a request, however the atrributes of that XML have to particular formats (string, int, boolean, dateTime etc). An example of my XML is as follows,

<Property>
    <Address>
        <AddressLine1>str1234</AddressLine1>
        <AddressLine2>str1234</AddressLine2>
        <AddressLine3>str1234</AddressLine3>
        <AddressLine4>str1234</AddressLine4>
        <PostCode>po75xa</PostCode>
        <RoyalMailReference>str1234</RoyalMailReference>
    </Address>
    <PropertyType>DetachedHouse</PropertyType>
    <NumberOfBedrooms>3</NumberOfBedrooms>
    <YearBuilt>1970</YearBuilt>
</Property>

The XML is stored in a Laravel view that load in like this,

$xml = simplexml_load_string( View::make('samplerequest') );

I then send the request to the API (it is via SOAP), the request I get back shows eve that actually gets sent shows every attribute is a string. How can I define what type each attribute is? Or will will simplexml_load_string() cast everything into a string?

Cycs
  • 229
  • 1
  • 5
  • 15
  • How does your `SoapClient::__soapCall()` method call looks like? – TiMESPLiNTER Jul 11 '14 at 07:25
  • `$response = $quote_soap->call( 'GetComparisonSchemaBound' , array('parameters' => $xml) , $service, $action);` – Cycs Jul 11 '14 at 07:30
  • You can't pass XML objects as paramters. You have to pass a paramName => value array with scalar data in it. – TiMESPLiNTER Jul 11 '14 at 07:32
  • So i need to turn my XML into an array? – Cycs Jul 11 '14 at 07:34
  • Exactly and convert your strings from the XML to data types which are required by the SoapServer. For example `NumberOfBedrooms` to `int`. – TiMESPLiNTER Jul 11 '14 at 07:35
  • Thanks @TiMESPLiNTER `$xml = simplexml_load_string( View::make('') ); $xmlcont = new SimpleXMLElement($xml);` returns "String could not be parsed as XML" any ideas why? – Cycs Jul 11 '14 at 07:38
  • `View::make('')` does not return a valid XML string. – TiMESPLiNTER Jul 11 '14 at 07:40
  • @TiMESPLiNTER one more question the SOAP api requests a dateTime datatype, it there a way to cast a value to this, I am setting the datetime with PHP and the array output is saying it is a string – Cycs Jul 11 '14 at 08:23
  • [See this post here](http://stackoverflow.com/a/18718862/1652031) It seems as it does matter what DateTime object is on SoapServer site. If it is a PHP SoapServer it is using the [`DateTime`](http://ch1.php.net/manual/en/class.datetime.php) class. If it is not PHP it can be very difficult to pass a valid `DateTime` object. – TiMESPLiNTER Jul 11 '14 at 08:33

0 Answers0