如何将PHP STDCLASS对象转换为XML?
我使用此代码连接到Web服务,该服务使我可以检索电子商务产品的库存。但是,后者返回一个stdclass对象(下图)。
$wsdl = "https://sinex-saas.com/blabla/Services/WebServiceStandard.asmx?WSDL";
$password = "????";
$username = "????";
$options = array(
'user' => $username,
'password' => $password,
);
$client = new SoapClient($wsdl);
$response = $client->RecupererEtatStock($options);
$presque = $response->RecupererEtatStockResult;
echo '<pre>';
print_r($presque);
我的目标是将此STDClass对象转换为XML,以便我可以将其用于WordPress插件。您知道如何使用PHP将stdclass转换为XML吗?
I use this code to connect to a web service that allows me to retrieve a stock of products for e-commerce. However, the latter returns a stdClass Object (photo below).
$wsdl = "https://sinex-saas.com/blabla/Services/WebServiceStandard.asmx?WSDL";
$password = "????";
$username = "????";
$options = array(
'user' => $username,
'password' => $password,
);
$client = new SoapClient($wsdl);
$response = $client->RecupererEtatStock($options);
$presque = $response->RecupererEtatStockResult;
echo '<pre>';
print_r($presque);
My goal is to convert this stdClass object to XML so that I can use it for a WordPress plugin. Do you know how to convert a stdClass to XML with PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要尝试构建通用转换。读取特定的对象结构并从中创建 DOM 会容易得多。这允许您定义结构、验证和重新格式化值、忽略不需要的值……
输出:
Don't try to build a generic convert. It is a lot easier just to read a specific object structure and create a DOM from it. This allows you to define the structure, validate and reformat the values, ignore unneeded values, ...
Output: