2011-08-08 47 views
0

我是salesforce新手。精通php,但我沒有做任何XML解析。我有這個我可以使用的文件。當銷售人員對象改變它創建:我如何使用PHP中的salesforce中的名稱空間使用SOAP消息

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<soapenv:Body> 
<notifications xmlns="http://soap.sforce.com/2005/09/outbound"> 
    <OrganizationId>00D30000000opwSEAQ</OrganizationId> 
    <ActionId>04k30000000L6QPAA0</ActionId> 
    <SessionId xsi:nil="true"/> 
    <EnterpriseUrl>https://na1-api.salesforce.com/services/Soap/c/22.0/00D30000000opwS</EnterpriseUrl> 
    <PartnerUrl>https://na1-api.salesforce.com/services/Soap/u/22.0/00D30000000opwS</PartnerUrl> 
    <Notification> 
    <Id>04l3000000JbKClAAN</Id> 
    <sObject xsi:type="sf:Account" xmlns:sf="urn:sobject.enterprise.soap.sforce.com"> 
    <sf:Id>0013000000ooziWAAQ</sf:Id> 
    <sf:BillingCity>New York</sf:BillingCity> 
    <sf:BillingCountry>US</sf:BillingCountry> 
    <sf:BillingPostalCode>10000</sf:BillingPostalCode> 
    <sf:BillingState>New York</sf:BillingState> 
    <sf:BillingStreet>302 E xxx St Apt C</sf:BillingStreet> 
    <sf:FN__Mapping_Status__c>Not Located Yet</sf:FN__Mapping_Status__c> 
    <sf:IsDeleted>false</sf:IsDeleted> 
    <sf:Member_Status__c>Active</sf:Member_Status__c> 
    <sf:Name>Joel Test</sf:Name> 
    </sObject> 
    </Notification> 
</notifications> 
</soapenv:Body> 
</soapenv:Envelope> 

我需要解析它,這樣我可以取值在SF命名空間和更新數據庫。我可以使用SimpleXML讀取命名空間中的東西,但是我無法讀取命名空間值。有人可以指點我的例子代碼或教程如何做到這一點?

回答

0

看起來這是來自Salesforce中的出站消息功能的SOAP消息。不要將其視爲僅將XML視爲XML,而應將本機PHP SoapServer與Salesforce中提供的WSDL一起使用,因爲它旨在處理像這樣的SOAP消息。您可以在Setup |上獲取WSDL創建|工作流程&認證|出站郵件| |端點WSDL。您可能還想看看Salesforce PHP Client,它使用相應的PHP SoapClient並具有一個用於處理sf:名稱空間並轉換爲SObject對象的實用程序。將工具包重新連接爲服務器而不是客戶端應該不會太難,因此您可以處理出站消息。

0

PHP的SimpleXML可能適用於這種情況。只需要使用children()並使用正確的語法。

因此,閱讀在Salesforce出站郵件字段值結算城市,你可以使用下面的代碼:

$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')->BillingCity 

爲了幫助你瞭解它是如何工作的,我寫的與薩姆斯代碼和XML後,其應更容易理解。

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

一旦你可以讀取歸檔值,您可以將其存儲到其他數據庫或文本文件用PHP。

相關問題