Reputation: 3
Anyone can help on this how I can get the value of callerId from this string?
String is pulled from php://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>
Upvotes: 0
Views: 731
Reputation: 11689
You can easily use DOMDocument
.
Assuming your string is in $xml
variable, try this code:
$dom = new DOMDocument();
$dom->loadXML( $xml, LIBXML_NOBLANKS );
$callerId = $dom->getElementsbyTagName( 'callerId' )->item(0)->nodeValue;
Upvotes: 1
Reputation: 163632
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:
$source = <<<SOURCE
<?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>
SOURCE;
$xml = simplexml_load_string($source);
$xml->registerXPathNamespace('ns2', 'http://authorization.wallet.de');
$elements = $xml->xpath('//S:Envelope/S:Body/ns2:authorizePlayer/authorizationRequest/callerId');
$element = $elements[0];
echo $element;
Will result in:
mycallerid
Upvotes: 0