Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    33
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Process Soap data as array instead of string

    Heya,

    I've got the following snippet:

    PHP Code:
    <?php
    $client 
    = new SoapClient("http://www.webservicex.net/globalweather.asmx?wsdl");

    $weather $client->GetCitiesByCountry(array("CountryName"=>"Germany"));
    $xml_str $weather->GetCitiesByCountryResult;

    $xml_str preg_replace('/Germany/'''$xml_str);

    echo 
    $xml_str;
    ?>
    It returns the result the following way:
    PHP Code:
    Berlin-Schoenefeld
    Dresden
    -Klotzsche
    Erfurt
    -Bindersleben
    Frankfurt 
    M-Flughafen
    Muenster 
    Osnabrueck
    Hamburg
    -Fuhlsbuettel
    Berlin
    -Tempelhof
    Koeln 
    Bonn
    Duesseldorf
    Munich 
    Riem
    Nuernberg
    ... 

    How can I store the parsed result as an array instead of a string (xml_str)?

    My plan is to loop through the result, like this:
    PHP Code:
    $i=0;
    foreach (
    $xml_str as $dataset)
    {
    echo (
    "Result " $i ": " $dataset);
    $i++;

    (just an example, I actually plan to parse the result into a selection box).

    another question:
    can I somehow avoid the line:
    PHP Code:
    $xml_str preg_replace('/Germany/'''$xml_str); 
    I only do it because the result would otherwise parse like this:
    PHP Code:
    GermanyBerlin-Schoenefeld
    GermanyDresden
    -Klotzsche
    GermanyErfurt
    -Bindersleben
    GermanyFrankfurt 
    M-Flughafen
    ... 

    Thanks in advance! 8)

  • #2
    New Coder
    Join Date
    Jul 2012
    Posts
    33
    Thanks
    18
    Thanked 0 Times in 0 Posts
    nevermind found it already,
    simplexml_load_string($xml_str); was the keyword I was looking for


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •