Accessing multiple responses in SOAP - php

I just learned soap a month ago and managed to get a reply in PHP. I managed to get a response and parse it but I am stuck with a different response where I get 5 instead of 1. Trying to figure out how to parse it. I'm so used to arrays and all that it's a bit confusing for me
Here is a normal response/reply
$value = $client->GetInmate($parameters);
$xml = $value->GetInmateResult;
print "Street: ".$xml->Address->Street;
print "<br>City: ".$xml->Address->City;
print "<br>State ".$xml->Address->State;
This works
Now I am trying to do something similar but my same method is not working, here is an image of the structure of the next reply:
http://i.stack.imgur.com/wWFxg.png
As you can see, I'm trying to get the 'Charges (5)' and manage them independently but racking my brain to do so. simplexml_load_string() isn't helping either, doesn't seem to parse them correctly.

Aren't you able to retrieve the result in the loop because it is the same format which i can see in the image attached. If not, then let me know the response which you are getting through this line:
$xml = $value->GetInmateResult

Related

Get SOAP response to xml

Stack Overflow is full with questions like this, I'm aware of that. But none of the questions and accepted answers have solved it for me.
I'm getting a SOAP response like this:
string(402482) "ZSDSD1BKA00_DE_02DE00010000001083212550JVBERi0xLjUNJeLjz9MNCjExNCAwIG9iag08PC9MaW5lYXJpemVkIDEvTCAxMDgzMjEvTyAxMTYv RSAxODY2Mi9OIDEyL1QgMTA3Nzk3L0ggWyA1MDMgMjc2XT4+DWVuZG9iag0gICAgICAgICAgICAg DQoxMzQgMCBvYmoNPDwvRGVjb2RlUGFybXM8PC9Db2x1bW5zIDQvUHJlZGljdG9yIDEyPj4vRmls dGVyL0ZsYXRlRGVjb2RlL0lEWzwxREZGRkVGMUM4Q0E0NTI4QjBBMUYxOUEyNTMwREQ2OD48RURD QTlGRDBFNTE4N0M0N0JGRUZCOEM0MjlCRTUwMjE+XS9JbmRleFsxMTQgMzZdL0luZm8gMTEzIDAg Ui9MZW5ndGggOTMvUHJldiAxMDc3OTgvUm9vdCAxMTUgMCBSL1NpemUgMTUwL1R5cGUvWFJlZi9X WzEgMiAxXT4+c3RyZWFtDQpo3mJiZBBgYGJg/g0kGEKABONRIMHiCiSYNEASK0DEG5AEP4i4CZKI ABHiQEJ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4MyQ HB6O5owk7knCCPcUETKCMSAiCGEMicdwjIinYPQZkZGEkZMogHW+IJxHOOHBIg8Fn3CJW31JhCfB 7BufaAmI53m4C7xKML9/T6dVXtXxJl1qVLbKQGDkK8ihgQHyeEw/vjSf4iZtcNWnmBtgdmZWlQ0Y k4QzAw/3Jokw0KzsG1BWVgaOlUMDxHp5qKtlrJtH+vBhRhP90tB5ka71dEG/f/nxn17iEfMCzhXS 7J4XSkIYhOo08CyiTgsAIXeaQryi0wRGyp47Hj/S+XR6m271CvYbNAswlSv9ghYbCyJ89GfutgAg Xx7Iv2m+1SDcEU7jSavGd4TdMEGTXxu9ixitNnZ+PIa9k+1Slw0JI06n6eZvna2fGsIZY/SDtlMj wRWd5el6SzzfhPf2tnp5HEl4/iOPQWLAatwSLMzsLC2y/NdfSVboLbnXP8nXqkjLd2buPi00NTMw YewP8V1ipuKm1s3yid5XdZHmxvTNovEBzLxJ82w5Kde5JozGjS7+IWF7M1yKYOts01Q1/d67hLki RhPXHDj4Y7msVlm5pt+yclJus06fZfW2mT6lNfHE3gEm+fHZfU7bJVwIGj//aBBMUj9rg6qDBr5X
... but much longer.
Then I use simplexml_load_string to convert it, resulting in an apparently empty object. Now I've learned that this object is not empty though. print_r and var_dump are of no help and I used simplexml_tree.php for help. But I'm now stuck on how I can access a property within the result. I tried a bunch of different variations, most of them left me either a blank page, or an error 500.
This is the response I expect:
Trying to access property ORBLK, like I wrote, with many variations, has not been successful. Thats my current try (resulting a blank page):
$resultRow = (string)$xml->children('soap-env', true)->Body->children('n0', true)->Z_SDB_GET_SDB_FOR_MATERIALResponse->T_SDB->item->DOKAR;
How would I be able to access the property ORBLK?

PHP won't receieve POST XML data

I'm building a service backend that is being sent a "delivery report" after successfully sending a SMS to a user.
The report itself is XML POSTed to our "endpoint" with the content-type application/xml.
I'm using Postman to make sure that everything is working correctly. I've made a test using regular JSON and can return the data without issues, however, no matter what I try with XML I basically get no indication that anything is being sent to the server.
(Test with JSON)
(Test with XML)
Here's my simple PHP script:
<?php
header('Content-Type: application/xml; charset=utf-8');
print_r(json_decode(file_get_contents("php://input"), true));
print_r($HTTP_RAW_POST_DATA);
?>
I feel like I've tried everything. Been looking at past issues posted to SO and other places, it simply won't work for me. I'm hoping for some answers that at least points me in the right direction here.
Cheers.
Your trying to json_decode XML data. You should use something like SimpleXML.
Instead of...
print_r(json_decode(file_get_contents("php://input"), true));
You should use ...
$xml = new SimpleXMLElement(file_get_contents("php://input"));
echo $xml->asXML();
You should be able to get the information by (for example)...
echo (string)$xml->id;
json_decode can't read XML, seems like you're trying to parse XML with json_decode. if you want to output the received XML, use echo (or if it's for debugging purposes, use var_dump, eg var_dump(file_get_contents("php://input"));), or if you want to parse the XML, use DOMDocument.

splitting apart response from an API

I am trying to start using APIs, doing calls and so forth. Just barely starting to learn. Found a way to get Facebook shares on a post using the graph api.
I did this with PHP; here is the code:
$response = file_get_contents('https://graph.facebook.com/? id=mydomain.com');
echo $response;
this is the response that I get:
{"id":"http://sportsmockery.com/2014/11/hey-bears-fire-everyone/","shares":22}
What I want is to somehow get the share count (22) into a variable so I can do stuff with it…(i changed the domain that gets that share count to my domain.com);
anyway; I am not sure what is the standard way to do this, if you control what is received with how you do your call; or if you just get the full response and pull out what you want…
Been looking around and have not been able to find anything that will really help with this.
I am hoping someone can help me with this…
All the best, G
Use json_decode() which will make all of the properties easily accessible.
$parsedResponse = json_decode($response);
$count = $parsedResponse->shares;
echo $count;
This is a json response.
Parsing JSON file with PHP
http://php.net/manual/en/function.json-decode.php

Php and XML connection(SimpleXML)

So im trying to make a connection with steam api and my site.Steam api returns format in XML, so i have created a connection via PHP to my server using simplexml.it is something like this:
$xml=simplexml_load_file("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=xxxxxxx&steamids=xxx&format=xml");
print $xml->response->players->player->steamid;
And the xml file code is :
<response><players><player><steamid>xxxx</steamid></response></players></player>
So in return I get nothing while i should get this number: xxxx
Also I can get whole document with print_r($xml); but taking only some tags seems not to work
Any tips?
Thanks in advance

How to parse this NOAA Weather Alert CAP in PHP?

Greetings,
I am having some difficulty understanding how to parse NOAA's Weather Alert CAP in PHP. I need to do the following:
Locate the proper county in the feed
Verify that there is an active alert
Display the alert's description
The feed I am working with is at this address - http://www.weather.gov/alerts/va.cap
I have used simplexml_load_string() in the past for this sort of thing but it does not seem to work for this feed.
Thanks!
After some more time on Google I came across a script that does exactly what I am trying to do. Rather than try to reinvent the wheel, I am going to go with it. http://saratoga-weather.org/scripts-atom.php#atomadvisory
You are probably having an issue due to the namespace
<cap:alert xmlns:cap='http://www.incident.com/cap/1.0'>
This should give you an idea of how to extract information
$sxe = simplexml_load_file('http://www.weather.gov/alerts/va.cap');
foreach ($sxe->getDocNamespaces() as $ns => $uri) {
$sxe->registerXPathNamespace($ns, $uri);
}
foreach($sxe->xpath('//cap:areaDesc') as $areaDesc) {
echo $areaDesc;
}
On a sidenote, SimpleXml is for simple XML only. Consider using DOM instead.

Categories