我想忽略" stdClass对象 ("以及最后一个")"在XML文件中。我是否在请求错误的情况下获取xml文件?
通过Soap请求创建xml文件:
$soap = new \SoapClient($request, $options);
$res = $soap->ExecuteQuery(['query' => $xmlQuery]);
$fileOpen = realpath(dirname(__FILE__) . '/..') . '/xmlFile.xml';
$fil = fopen($fileOpen, "a");
fwrite($fil, print_r($res, true));
fclose($fil);
创建的xmlFile.xml:
stdClass Object
(
[ExecuteQueryResult] => <?xml version="1.0" encoding="utf-8"?>
<Data totalExecutionTime="00:00:13.1123107">
<Product id="84650" ... >
...
</Product>
</Data>
)
尝试使用它来读取xml文件:
$xml1 = new \XMLReader();
$xml1->open(realpath(dirname(__FILE__) . '/..') . '/xmlFile.xml');
我最终收到此错误:
Warning: XMLReader::open() expects parameter 1 to be a valid path, object given on
"$xml1->open(realpath(dirname(__FILE__) . '/..') . '/xmlFile.xml');"
答案 0 :(得分:2)
SOAP返回stdClass对象。基于var_dump()
,您似乎需要访问ExecuteQueryResult
属性才能获取XML字符串。
因此,试一试:
$xml = $res->ExecuteQueryResult;
fwrite($fil, $xml);
答案 1 :(得分:1)
fwrite($fil, $res->ExecuteQueryResult);
$soap->ExecuteQuery
会返回一个对象,您只对ExecuteQueryResult
字段感兴趣。