微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP-simplexml帮助我该如何解析?

我还没有完成任何xml项目,所以我不太确定如何处理这些数据…

我正在使用curl向salesforce发出请求,并且它们给了我需要解析的响应.我想使用simplexml.这是响应的一部分:

<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>

无论如何,我希望将这些东西(我们称之为数据)输入

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

那样就可以将所有数据都给我…然后访问特定部分,将是$results-> body-> loginResponse-> blah-> blah …

但这并没有给我,也没有给我任何回报,只是一个空的简单xml对象…

因此,一个网站使我认为我可能需要XSLT才能正确阅读此内容.
或其他原因使我认为这是因为我没有最高职位.

救命!

解决方法:

您可以使用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;

最后,重要的是,您是否看过salesforce的tools & examples

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐