我正在尝试显示来自 SOAP API 的多条记录。我的电话工作正常,这是预期的 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>
<GetDataResponse xmlns="urn:com:esi911:webeoc7:api:1.0">
<GetDataResult>
<data>
<record dataid="6" county="Fayette County" title="Title goes here" description="Description goes here." status="Inactive" />
<record dataid="5" county="Caldwell County" title="Title goes here" description="Description goes here." status="Inactive" />
<record dataid="4" county="Burnet County" title="Title goes here" description="Description goes here." status="Active" />
<record dataid="2" county="Blanco County" title="Title goes here" description="Description goes here." status="Active" />
<record dataid="1" county="Bastrop County" title="Title goes here" description="Description goes here." status="Active" />
</data>
</GetDataResult>
</GetDataResponse>
</soap:Body>
</soap:Envelope>
现在,我只想在我的网页上显示这些记录中的第一个及其属性。我将此响应扔到 SimpleXML 中,并尝试获取要显示的多个属性。这是我迄今为止基于各种其他 StackOverflow 示例所做的尝试,但没有一个真正符合我上面的确切 XML 响应结构:
$xml = simplexml_load_string($response);
$response = $xml->xpath("//soap:Body/*")[0];
$result = $response->children("urn:com:esi911:webeoc7:api:1.0");
echo (string) $result->data->record[0]->attributes()->dataid;
我没有收到任何具体的错误。它总是空白,什么都没有显示。
最终,我需要遍历这些记录以将它们全部显示或将它们存储到自己的数组中以供以后使用,但我似乎什至无法从上面的代码中回显任何内容。我确定这可能与多个名称空间有关?或者只是某个地方的基本错字?
任何有关此 XML 响应的建议都会很棒。谢谢!
慕莱坞森
慕雪6442864