好的,所以我使用 SOAP 从服务中请求状态和城市,并使用“foreach”循环来输出状态,并且在每次迭代中,我使用另一个“foreach”循环来输出每个州内的城市.
首先,SOAP 调用:
$client = new SoapClient("https://devxml.#####.com/golfService.asmx?wsdl", array(‘features’ => SOAP_SINGLE_ELEMENT_ARRAYS));
$regionList = $client->Areas(
array(
'Hdr' => array(
'ResellerId' => '#####',
'SourceCd' => 'A',
'UserIp' => '207.58.123.121',
'gsDebug' => '1'
),
'Req' => array(
'CountryID' => 'USA',
'RegionID' => ''
)
)
)
...返回以下 XML:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AreasResponse xmlns="http://xml.####.com/">
<AreasResult>
<RetCd>0</RetCd>
<RetMsg />
<Countries>
<Country>
<id>USA</id>
<nm>United States</nm>
<Regions>
<Region>
<id>AZ</id>
<nm>Arizona</nm>
<Areas>
<Area>
<id>Phoenix Northeast</id>
<nm>Phoenix Northeast</nm>
</Area>
</Areas>
</Region>
<Region>
<id>FL</id>
<nm>Florida</nm>
<Areas>
<Area>
<id>Ft. Myers/Naples</id>
<nm>Ft. Myers/Naples</nm>
</Area>
<Area>
<id>Miami / Ft. Lauderdale</id>
<nm>Miami / Ft. Lauderdale</nm>
</Area>
</Areas>
</Region>
</Regions>
</Country>
</Countries>
</AreasResult>
</AreasResponse>
</soap:Body>
</soap:Envelope>
现在,这是我在 PHP 中处理这个问题的方式:
foreach ($regionList->AreasResult->Countries->Country->Regions->Region as $region):
echo $region->nm . ": ";
foreach ($region->Areas->Area as $area):
echo $area->nm . ", ";
endforeach;
echo "<br />";
endforeach;
理想情况下,这将输出为:
亚利桑那州:凤凰城东北部,
佛罗里达州:英尺。迈尔斯/那不勒斯,迈阿密/英尺。劳德代尔,
但不是!它是这样显示的:
亚利桑那州:,
佛罗里达州:英尺。迈尔斯/那不勒斯,迈阿密/英尺。劳德代尔,
“Arizona:”后面的两个逗号表示有两条记录,但只有一条。更可气的是它不会输出dang Area值。我究竟做错了什么?帮助我,StackOverflow,你是我唯一的希望!