Simplexml help How do I parse this?

I have not done any xml projects, so I'm not quite sure what to do with this data ...

I use curl to make a request to salesforce, and they will return me the answer that I need to analyze. I want to use simplexml. Here is part of the answer:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<loginResponse>
<result>
<metadataServerUrl>
https://na6-api.salesforce.com/services/Soap/m/18.0/
</metadataServerUrl>
<passwordExpired>
false
</passwordExpired>
<sandbox>
false
</sandbox>
<serverUrl>
https://na6-api.salesforce.com/services/Soap/u/18.0/
</serverUrl>
<sessionId>
!AQ4AQLtDIqY.
</sessionId>
<userId>

</userId>
<userInfo>
<accessibilityMode>
false
</accessibilityMode>
<currencySymbol>
$
</currencySymbol>
<orgDefaultCurrencyIsoCode>
USD
</orgDefaultCurrencyIsoCode>
<orgDisallowHtmlAttachments>
false
</orgDisallowHtmlAttachments>
<orgHasPersonAccounts>
false
</orgHasPersonAccounts>
<organizationId>

</organizationId>
<organizationMultiCurrency>
false
</organizationMultiCurrency>
<organizationName>
Ox 
</organizationName>
<profileId>
sdfgsdfg
</profileId>
<roleId>
sdfgsdfg
</roleId>
<userDefaultCurrencyIsoCode xsi:nil="true"/>
<userEmail>
###@gmail.com
</userEmail>
<userFullName>
### ###
</userFullName>
<userId>
asdfasdf
</userId>
<userLanguage>
en_US
</userLanguage>
<userLocale>
en_US
</userLocale>
<userName>
asdfasdf@gmail.com
</userName>
<userTimeZone>
America/Chicago
</userTimeZone>
<userType>
Standard
</userType>
<userUiSkin>
Theme3
</userUiSkin>
</userInfo>
</result>
</loginResponse>
</soapenv:Body>
</soapenv:Envelope>

In any case, I expected that this material (we will call it) will be transferred to

$results = simplexml_load_string($data);
var_dump($results);

And this will give me all the data back ... and then for access to certain parts, it will be $ results-> body-> loginResponse-> blah-> blah ...

But this does not give me this, it does not give me anything, just an empty simple xml object ...

, - , XSLT, .
- , .

Help!

+3
8

SimpleXML, , , - (, soapenv). SimpleXMLElement::children, :

$sxe = new SimpleXMLElement($data);
$login_response = $sxe->children('soapenv', TRUE)->Body->children('', TRUE)->loginResponse->result;
// Now that we have the <loginResponse> lets take a look at an item within it
echo $login_response->userInfo->userEmail;

, , ,

+1

SimpleXML XML (ref.)

+2

,

. , php soapclient, , .

$results = simplexml_load_string($data);
$xml = $results->children('http://schemas.xmlsoap.org/soap/envelope/');
var_dump($xml);

, .

+1

, PHP SoapClient . O'Reilly PHP SOAP.

0

PHP Toolkit SOAP Salesforce.com

0

salathe. ('soapenv', TRUE) , Jason children ('http://schemas.xmlsoap.org/soap/envelope/ ').

, CreateDate Salesforce Outbound Message, :

$rcXML->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://soap.sforce.com/2005/09/outbound')->notifications->Notification->sObject->children('urn:sobject.enterprise.soap.sforce.com')->CreatedDate

, , sames xml, .

http://amigotechnotes.wordpress.com/2013/11/16/parse-xml-with-namespace-by-simplexml-in-php/

0

SimpleXML XML XML .

, RateResponse API UPS, :

// $client is your SoapClient object

$dom = new DOMDocument;

$dom->loadXML($client->__getLastResponse());

$xml = simplexml_load_string($dom->saveXML(), NULL, NULL, 'http://schemas.xmlsoap.org/soap/envelope/');

$RateResponse = $xml->xpath('/soapenv:Envelope/soapenv:Body')[0]->children('rate', true)->RateResponse;

foreach($RateResponse->RatedShipment as $RatedShipment) {
    print_r((array)$RatedShipment);
}
0

SAOP , SOAP-ENV: blank

$response = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>';

$response = html_entity_decode($response);
$response = str_replace(['soapenv:', 'ns1:', ':ns1', 'SOAP-ENV:'], ['', '', '', ''], $response);
$objXmlData = simplexml_load_string($response);
0

Source: https://habr.com/ru/post/1744242/


All Articles