2011-11-15 151 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