You are here:  » Loading a soap response into a string


Loading a soap response into a string

Submitted by waltonp on Mon, 2011-03-14 12:04 in

Hi

Im writing a script to process a soap request, put into a string variable and then use magic parser to process the xml.
The only way I can get magic parser to parse the xmland print the elements on screen is to write the response to a file and use:

MagicParser_parse($myFile,"test","xml|FEATURES/FEATURE/")

which works fine. Id like to use the string function option to process the xml response to make the script a little quicker rather than writing to a file first, but it does not work:

MagicParser_parse("string://".$url,"test","xml|FEATURES/FEATURE/");

$url holds the xml as a string

example xml string:

DetachedNonSmokingFourPosterEnclosedGardenPrivateHotTubIndoorPoolOutdoorPoolGamesRoomMultiBathShowerPubCloseByFishingOnSiteSandyBeach5MilesSea5MilesWheelchairAccessOpenFireShortBreakRomanticBreakUltimatePetFriendlyEasyWalkingAccess

I cant see why the "string://" option doesnt work.

Can you help?

Submitted by support on Mon, 2011-03-14 12:17

Hi,

Under normal circumstances, Magic Parser should be able to retrieve the URL
directly so there would be no need for string:// at all - just use:

MagicParser_parse($url,"test","xml|FEATURES/FEATURE/");

If that doesn't work, it's most likely that URL wrappers are not enabled in
your PHP installation - more information on that on the following page:

http://uk2.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen

However, it is becoming more common for CURL to be installed and available
to PHP, which is an alternative method for accessing remote URLs. In place
of the above code, have a go with:

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $xml = curl_exec($ch);
  curl_close($ch);
  MagicParser_parse("string://".$xml,"test","xml|FEATURES/FEATURE/");

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by waltonp on Mon, 2011-03-14 13:15

Hi

I used url as a variable string which is misleading. Its not a url as such just a variable string used in my code. The string option should work but it doesnt and i cant see why.

thx

Submitted by waltonp on Mon, 2011-03-14 15:40

Hi

The url variable above is misleading. Its just a string and not a url address.

Submitted by support on Mon, 2011-03-14 15:53

Hi,

Double check that there is no white space leading or trailing the XML as that may
have been stripped in the file save process - have a go with:

  $url = trim($url);
  MagicParser_parse("string://".$url,"test","xml|FEATURES/FEATURE/");

Hope this helps,
Cheers,
David.