Eduardo Fuerte
asked on
Could you point a way to transverse this SoapVar Object containing a XML by using PHP ?
Hi Experts
Could you point a way to transverse this SoapVar Object by using PHP to obtain the values expressed by
pdf_coupon_title
pdf_promotionid
pdf_barcode ?
Thanks in advance
Could you point a way to transverse this SoapVar Object by using PHP to obtain the values expressed by
pdf_coupon_title
pdf_promotionid
pdf_barcode ?
SoapVar Object
(
[enc_type] => 147
[enc_value] => <payment_request_response_code value="9230">
<transaction_uid value="93163"/>
<date value="20210121"/>
<hour value="10:29:07"/>
<number_of_coupons value="0"/>
<coupons>
</coupons>
<store_number value="0104"/>
<ptv_number value="0038"/>
<point_balance value="0"/>
<point_unusable value="0"/>
<city_code value=""/>
<pdf_coupons>
<pdf_coupon pdf_coupon_title="Teste" pdf_promotionid="14" pdf_barcode="29600104210121000131" pdf_ean_type="EAN128" pdf_amount="29.67" pdf_text="VGVzdGUKCnRlc3RlCnRlc3RlCgpDVVBPTSBWQUxJRE8gREU6IDIwLzAxLzIwMjEgQVRFIDIwLzAx LzIwMjIKRU0gVE9EQVMgQVMgTE9KQVMKCiAgICAgICAgICAgICAgICAgICAgIHRlc3RlCiAgICAg ICAgICAgICAgICAgICAgIHRlc3RlCiAgICAgICAgICAgICAgICAgICAgIHRlc3RlCiAgICAgICAg ICAgICAgICAgIC AgIHRlc3RlCiAgICAgICAgICAgICAgICAgICAgIHRlc3RlCiAgICAgICAgICAg ICAgICAgICAgIHRlc3RlCiAgICAgICAgICAgICAgICAgICAgIHRlc3RlCiAgICAgICAgICAgICAg ICAgICAgIHRlc3RlCiAgICAgICAgICAgICAgICAgICAgIHRlc3RlCiAgICAgICAgICAgICAgICAg ICAgIHRlc3RlCiAgICAgICiAx NAo="/>
</pdf_coupons>
<management_coupon>
CiAgICAgICAgICAgICAgICAgICAgUFJPTU9DQU8gICAgICAgICAgICAgICAgICAgIAoKUFJPTU9D
QU8gQ09OQ0VESURBIE5PUyBQUk9EVVRPUyBBQkFJWE8gOgoKSVRFTSBDT0RJR08gREVTQ1J
ICAgICAgICAgICAgICAgICAVEVNIFIkClBST01PQ0FPIG9mZmVyXzFfY2xhc3NpY19sb3Qg
ICAgICAgICAgICAgIC0yOC43
OQogIDAwNCA3NjkzNzQ1ICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgLTcuMjAKICAwMDUgNzY5Mzc1MyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC03
LjIwCiAgMDA2IDc2OTM3NjEgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0xNC4zOQ==
</management_coupon>
</payment_request_response_code>
)
Another thing needed is to determine if the XML contains or not <pdf_coupon>Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The code should work for that scenario.
ASKER
Ok.
Not clear for me:
enc_value is the name of the node, ok?
That error occurs:
SimpleXMLElement::__constr uct() expects parameter 1 to be string, object given
$response = new SimpleXMLElement($x);
Not clear for me:
$xml = $x->enc_value; // <-- Your raw XML string
enc_value is the name of the node, ok?
That error occurs:
SimpleXMLElement::__constr
$response = new SimpleXMLElement($x);
SoapVar is just a little helper/wrapper class that helps you construct the XML used within a SOAP communication. The "enc_value" property contains the raw XML inside of it:
ASKER
Runs....
SimpleXMLElement Object
(
[0] => Teste
)
SimpleXMLElement Object
(
[0] => 14
)
SimpleXMLElement Object
(
[0] => 29600104210121000177
)
ASKER
Just one final thing....
To obtain just the string value I tried
And
Also
No results...
How could I do that ?
To obtain just the string value I tried
$pdf_coupon["pdf_coupon_title"][0]
And
$pdf_coupon["pdf_coupon_title"]->enc_value
Also
(array) $pdf_coupon["pdf_coupon_title"]
Array
(
[0] => Teste
)
Array
(
[0] => 14
)
Array
(
[0] => 29600104210121000201
)
No results...
How could I do that ?
Sorry, I should have mentioned that in my initial response. Just add (string) before it:
So instead of something like:
$title = $pdf_coupon["pdf_coupon_title"];
...do this instead:
$title = (string)$pdf_coupon["pdf_coupon_title"];
SimpleXml has some unusual behavior with some things. Basically, it wants to handle everything with classes, but when you add (string) to the beginning, you're telling it, "I want the value of this element / attribute as a string, not as an object!" It's a process called "casting".
So instead of something like:
$title = $pdf_coupon["pdf_coupon_title"];
...do this instead:
$title = (string)$pdf_coupon["pdf_coupon_title"];
SimpleXml has some unusual behavior with some things. Basically, it wants to handle everything with classes, but when you add (string) to the beginning, you're telling it, "I want the value of this element / attribute as a string, not as an object!" It's a process called "casting".
ASKER
Perfect !!!
Teste
14
29600104210121000238
ASKER
gr8gonzo
Thank you for so good solution!!!
Thank you for so good solution!!!
ASKER
We always have one or none <pdf_coupon> entries