Read soap xml with php
983
Anyone can help on this how I can get the value of callerId from this string?
String is pulled fromphp://input
and i need this with just php without soap class and only this one value no loop.
Any idea?
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:authorizePlayer xmlns:ns2="http://authorization.wallet.de">
<authorizationRequest>
<callerId>mycallerid</callerId>
<callerPassword>mypassword</callerPassword>
<playerName>player</playerName>
<sessionToken>b0f4617bb56f1ed4706908b6ab9a4960</sessionToken>
</authorizationRequest>
</ns2:authorizePlayer>
</S:Body>
</S:Envelope>
Answer
Solution:
You can easily use
DOMDocument
.Assuming your string is in
$xml
variable, try this code:eval.in demo
Answer
Solution:
Another option is to use the SimpleXMLElement's xpath method and register the namespace.
$element
is of type SimpleXMLElement and you can call its __toString() method to return the string content:Will result in: