简体   繁体   English

PHP-如何从SOAP XML读取数据

[英]PHP - How to read data from SOAP XML

I have code for read XML SOAP 1.2 from web service. 我有用于从Web服务读取XML SOAP 1.2的代码。 Im using this: https://stackoverflow.com/a/18580428/2629513 我正在使用这个: https : //stackoverflow.com/a/18580428/2629513

I get this code below: 我在下面获得此代码:

 SimpleXMLElement Object
(
[OdkazyResponse] => SimpleXMLElement Object
    (
        [OdkazyResult] => SimpleXMLElement Object
            (
                [odkazy] => SimpleXMLElement Object
                    (
                        [odkaz] => Array
                            (
                                [0] => SimpleXMLElement Object
                                    (
                                        [@attributes] => Array
                                            (
                                                [kod_zbozi] => 31400001
                                                [typ] => OBR1
                                                [popis] => Oki ML 280 - foto
                                                [url] => http://www.atcomp.cz/katalog/31400001/ML280.gif
                                            )

                                    )

                                [1] => SimpleXMLElement Object
                                    (
                                        [@attributes] => Array
                                            (
                                                [kod_zbozi] => EC376123GB
                                                [typ] => OBR1
                                                [popis] => Malý obrázek
                                                [url] => http://www.atcomp.cz/katalog/EC376123GB/lq-680_-_maly.jpg
                                            )

                                    )

                                [2] => SimpleXMLElement Object
                                    (
                                        [@attributes] => Array
                                            (
                                                [kod_zbozi] => EC376123GB
                                                [typ] => OBR2
                                                [popis] => Velký obrázek
                                                [url] => http://www.atcomp.cz/katalog/EC376123GB/lq-680_-_velky.jpg
                                            )

                                    )

And how I can read the [kod_zbozi], [typ], [popis], [url] attributes? 以及如何读取[kod_zbozi],[typ],[popis]和[url]属性? I need to save it into my mysql database (this is not problem, the problem is read the data from this format XML). 我需要将其保存到我的mysql数据库中(这不是问题,问题是从这种XML格式读取数据)。 Thanks. 谢谢。

Well, the very first thing you might want to do is to convert that object into an array (to avoid naming problems) 好吧,您可能要做的第一件事就是将对象转换为数组(以避免命名问题)

You can use this function to do that: 您可以使用此功能来做到这一点:

  function object2array($object) { 
    return json_decode(json_encode($object), true); 
  }

then something like this: 然后是这样的:

$data = object2array(simplexml_load_string('....'));

print_r($data); // Its regular array now, use it keys to access values, then simply insert them into db

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM