2011-11-15 189 views
-3

我使用的API,我得到這樣的回答:如何解析這個SOAP響應

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'> 
<env:Header> 
</env:Header> 
<env:Body> 
<ns1:processRequestResponse xmlns:ns1='ejb.store.microsoft.com'> 
<result> 
<?xml version="1.0" encoding="UTF-8"?> <CRMMessage language="en_US" currency="USD" isTrustedSAT="false" hostversion="1.00"><RequestCode>GetCustomer</RequestCode><ResponseCode>A</ResponseCode><ResultSet><ResultSetMetaData><RSColumn name="PrimaryPOSRef" type="string" nullable="true"></RSColumn><RSColumn name="FirstName" type="string" nullable="true"></RSColumn><RSColumn name="LastName" type="string" nullable="true"></RSColumn><RSColumn name="EmailAddress" type="string" nullable="true"></RSColumn><RSColumn name="MobilePhoneNumber" type="string" nullable="true"></RSColumn><RSColumn name="Gender" type="string" nullable="true"></RSColumn><RSColumn name="PostalCode" type="string" nullable="true"></RSColumn><RSColumn name="PMACode" type="string" nullable="true"></RSColumn></ResultSetMetaData><Rows><Row id="11551"><Col>0331200000000058</Col><Col>test</Col><Col>Test</Col><Col>[email protected]</Col><Col>0412345678</Col><Col>M</Col><Col>2000</Col><Col>test</Col></Row></Rows></ResultSet></CRMMessage> 
</result> 
</ns1:processRequestResponse> 
</env:Body> 
</env:Envelope> 

什麼有用的是我如何解析這個

<result></result> 

之間的部分XML?

+1

http://stackoverflow.com/search?q=parse+soap+response+php – Gordon

+0

這不是(有效)的XML,由於該聲明作爲結果元素的子元素。 – Andy

回答

0

最簡單和直接的方法是將xml解析成數組,然後使用標籤作爲數組索引。你可以找到與此相關的一些在這裏的PHP類:

http://www.phpclasses.org/search.html?words=xml++array &限制[0] = C &限制[1] = B &限制[2] = d &論壇= F & go_search = 1 &先進= 1