我将SOAP响应转换为xml对象时遇到问题。 响应以字符串形式出现,但它具有xml结构:
HTTP/1.1 200 Connection established
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 20 Jul 2016 10:36:01 GMT
Content-Length: 14169
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCurrentExchangeRateResponse xmlns="http://communicationoffice.nbs.rs"><GetCurrentExchangeRateResult><xs:schema id="ExchangeRateDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"><xs:element name="ExchangeRateDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="ExchangeRate"><xs:complexType><xs:sequence><xs:element name="ExchangeRateListNumber" type="xs:int" /><xs:element name="Date" msdata:ReadOnly="true" minOccurs="0"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="10" /></xs:restriction></xs:simpleType></xs:element><xs:element name="CreateDate" msdata:ReadOnly="true" minOccurs="0"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="10" /></xs:restriction></xs:simpleType></xs:element><xs:element name="DateTo" msdata:ReadOnly="true" minOccurs="0"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="10" /></xs:restriction></xs:simpleType></xs:element><xs:element name="ExchangeRateListTypeID" type="xs:int" /><xs:element name="CurrencyGroupID" type="xs:short" minOccurs="0" /><xs:element name="CurrencyCode" type="xs:int" /><xs:element name="CurrencyCodeNumChar" msdata:ReadOnly="true" minOccurs="0"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="50" /></xs:restriction></xs:simpleType></xs:element><xs:element name="CurrencyCodeAlfaChar"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="6" /></xs:restriction></xs:simpleType></xs:element><xs:element name="CurrencyNameSerCyrl"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="60" /></xs:restriction></xs:simpleType></xs:element><xs:element name="CurrencyNameSerLat" minOccurs="0"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="60" /></xs:restriction></xs:simpleType></xs:element><xs:element name="CurrencyNameEng" minOccurs="0"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="60" /></xs:restriction></xs:simpleType></xs:element><xs:element name="CountryNameSerCyrl" msdata:ReadOnly="true" minOccurs="0"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="100" /></xs:restriction></xs:simpleType></xs:element><xs:element name="CountryNameSerLat" msdata:ReadOnly="true" minOccurs="0"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="60" /></xs:restriction></xs:simpleType></xs:element><xs:element name="CountryNameEng" msdata:ReadOnly="true" minOccurs="0"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="60" /></xs:restriction></xs:simpleType></xs:element><xs:element name="Unit" type="xs:int" /><xs:element name="BuyingRate" type="xs:decimal" minOccurs="0" /><xs:element name="MiddleRate" type="xs:decimal" minOccurs="0" /><xs:element name="SellingRate" type="xs:decimal" minOccurs="0" /><xs:element name="FixingRate" msdata:ReadOnly="true" type="xs:decimal" minOccurs="0" /></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema><diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><ExchangeRateDataSet xmlns=""><ExchangeRate diffgr:id="ExchangeRate1" msdata:rowOrder="0"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>2</CurrencyGroupID><CurrencyCode>978</CurrencyCode><CurrencyCodeNumChar>978</CurrencyCodeNumChar><CurrencyCodeAlfaChar>EUR</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Евро</CurrencyNameSerCyrl><CurrencyNameSerLat>Evro</CurrencyNameSerLat><CurrencyNameEng>Euro</CurrencyNameEng><CountryNameSerCyrl>ЕМУ</CountryNameSerCyrl><CountryNameSerLat>EMU</CountryNameSerLat><CountryNameEng>EMU</CountryNameEng><Unit>1</Unit><BuyingRate>122.8780</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>123.6174</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate2" msdata:rowOrder="1"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>36</CurrencyCode><CurrencyCodeNumChar>036</CurrencyCodeNumChar><CurrencyCodeAlfaChar>AUD</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Аустралијски долар</CurrencyNameSerCyrl><CurrencyNameSerLat>Australijski dolar</CurrencyNameSerLat><CurrencyNameEng>Australian Dollar</CurrencyNameEng><CountryNameSerCyrl>Аустралија</CountryNameSerCyrl><CountryNameSerLat>Australija</CountryNameSerLat><CountryNameEng>Australia</CountryNameEng><Unit>1</Unit><BuyingRate>83.6531</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>84.1565</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate3" msdata:rowOrder="2"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>124</CurrencyCode><CurrencyCodeNumChar>124</CurrencyCodeNumChar><CurrencyCodeAlfaChar>CAD</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Канадски долар</CurrencyNameSerCyrl><CurrencyNameSerLat>Kanadski dolar</CurrencyNameSerLat><CurrencyNameEng>Canadian Dollar</CurrencyNameEng><CountryNameSerCyrl>Канада</CountryNameSerCyrl><CountryNameSerLat>Kanada</CountryNameSerLat><CountryNameEng>Canada</CountryNameEng><Unit>1</Unit><BuyingRate>85.6472</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>86.1626</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate4" msdata:rowOrder="3"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>156</CurrencyCode><CurrencyCodeNumChar>156</CurrencyCodeNumChar><CurrencyCodeAlfaChar>CNY</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Јуан</CurrencyNameSerCyrl><CurrencyNameSerLat>Juan</CurrencyNameSerLat><CurrencyNameEng>Yuan Renminbi</CurrencyNameEng><CountryNameSerCyrl>Кина</CountryNameSerCyrl><CountryNameSerLat>Kina</CountryNameSerLat><CountryNameEng>China</CountryNameEng><Unit>1</Unit><BuyingRate>16.6781</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>16.7785</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate5" msdata:rowOrder="4"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>208</CurrencyCode><CurrencyCodeNumChar>208</CurrencyCodeNumChar><CurrencyCodeAlfaChar>DKK</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Данска круна</CurrencyNameSerCyrl><CurrencyNameSerLat>Danska kruna</CurrencyNameSerLat><CurrencyNameEng>Danish Krone</CurrencyNameEng><CountryNameSerCyrl>Данска</CountryNameSerCyrl><CountryNameSerLat>Danska</CountryNameSerLat><CountryNameEng>Denmark</CountryNameEng><Unit>1</Unit><BuyingRate>16.5125</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>16.6119</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate6" msdata:rowOrder="5"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>392</CurrencyCode><CurrencyCodeNumChar>392</CurrencyCodeNumChar><CurrencyCodeAlfaChar>JPY</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Јен</CurrencyNameSerCyrl><CurrencyNameSerLat>Jen</CurrencyNameSerLat><CurrencyNameEng>Yen</CurrencyNameEng><CountryNameSerCyrl>Јапан</CountryNameSerCyrl><CountryNameSerLat>Japan</CountryNameSerLat><CountryNameEng>Japan</CountryNameEng><Unit>100</Unit><BuyingRate>105.1227</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>105.7553</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate7" msdata:rowOrder="6"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>578</CurrencyCode><CurrencyCodeNumChar>578</CurrencyCodeNumChar><CurrencyCodeAlfaChar>NOK</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Норвешка круна</CurrencyNameSerCyrl><CurrencyNameSerLat>Norveška kruna</CurrencyNameSerLat><CurrencyNameEng>Norwegian Krone</CurrencyNameEng><CountryNameSerCyrl>Норвешка</CountryNameSerCyrl><CountryNameSerLat>Norveška</CountryNameSerLat><CountryNameEng>Norway</CountryNameEng><Unit>1</Unit><BuyingRate>13.1215</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>13.2005</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate8" msdata:rowOrder="7"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>643</CurrencyCode><CurrencyCodeNumChar>643</CurrencyCodeNumChar><CurrencyCodeAlfaChar>RUB</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Руска рубља</CurrencyNameSerCyrl><CurrencyNameSerLat>Ruska rublja</CurrencyNameSerLat><CurrencyNameEng>Russian Ruble</CurrencyNameEng><CountryNameSerCyrl>Руска Федерација</CountryNameSerCyrl><CountryNameSerLat>Ruska Federacija</CountryNameSerLat><CountryNameEng>Russian Federation</CountryNameEng><Unit>1</Unit><BuyingRate>1.7580</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>1.7686</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate9" msdata:rowOrder="8"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>752</CurrencyCode><CurrencyCodeNumChar>752</CurrencyCodeNumChar><CurrencyCodeAlfaChar>SEK</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Шведска круна</CurrencyNameSerCyrl><CurrencyNameSerLat>Švedska kruna</CurrencyNameSerLat><CurrencyNameEng>Swedish Krona</CurrencyNameEng><CountryNameSerCyrl>Шведска</CountryNameSerCyrl><CountryNameSerLat>Švedska</CountryNameSerLat><CountryNameEng>Sweden</CountryNameEng><Unit>1</Unit><BuyingRate>12.9432</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>13.0210</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate10" msdata:rowOrder="9"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>756</CurrencyCode><CurrencyCodeNumChar>756</CurrencyCodeNumChar><CurrencyCodeAlfaChar>CHF</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Швајцарски франак</CurrencyNameSerCyrl><CurrencyNameSerLat>Švajcarski franak</CurrencyNameSerLat><CurrencyNameEng>Swiss Franc</CurrencyNameEng><CountryNameSerCyrl>Швајцарска</CountryNameSerCyrl><CountryNameSerLat>Švajcarska</CountryNameSerLat><CountryNameEng>Switzerland</CountryNameEng><Unit>1</Unit><BuyingRate>113.1160</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>113.7968</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate11" msdata:rowOrder="10"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>826</CurrencyCode><CurrencyCodeNumChar>826</CurrencyCodeNumChar><CurrencyCodeAlfaChar>GBP</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Фунта стерлинга</CurrencyNameSerCyrl><CurrencyNameSerLat>Funta sterlinga</CurrencyNameSerLat><CurrencyNameEng>Pound Sterling</CurrencyNameEng><CountryNameSerCyrl>Велика Британија</CountryNameSerCyrl><CountryNameSerLat>Velika Britanija</CountryNameSerLat><CountryNameEng>United Kingdom</CountryNameEng><Unit>1</Unit><BuyingRate>146.1267</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>147.0061</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate><ExchangeRate diffgr:id="ExchangeRate12" msdata:rowOrder="11"><ExchangeRateListNumber>137</ExchangeRateListNumber><Date>20.07.2016</Date><CreateDate>20.07.2016</CreateDate><DateTo>31.12.4172</DateTo><ExchangeRateListTypeID>1</ExchangeRateListTypeID><CurrencyGroupID>3</CurrencyGroupID><CurrencyCode>840</CurrencyCode><CurrencyCodeNumChar>840</CurrencyCodeNumChar><CurrencyCodeAlfaChar>USD</CurrencyCodeAlfaChar><CurrencyNameSerCyrl>Амерички долар</CurrencyNameSerCyrl><CurrencyNameSerLat>Američki dolar</CurrencyNameSerLat><CurrencyNameEng>US Dollar</CurrencyNameEng><CountryNameSerCyrl>САД</CountryNameSerCyrl><CountryNameSerLat>SAD</CountryNameSerLat><CountryNameEng>United States </CountryNameEng><Unit>1</Unit><BuyingRate>111.5247</BuyingRate><MiddleRate>0.0000</MiddleRate><SellingRate>112.1959</SellingRate><FixingRate>0.000000</FixingRate></ExchangeRate></ExchangeRateDataSet></diffgr:diffgram></GetCurrentExchangeRateResult></GetCurrentExchangeRateResponse></soap:Body></soap:Envelope>
在此之后作为答案,我尝试将其转换为xml对象,如下所示:
$str = strstr($client->response, '<'); // telling it to cut away everything before <?xml tag
$xml_obj = simplexml_load_string($str); // loading string as xml
当我 var_dump($ xml_obj)时,我得到这个答案: 对象(的SimpleXMLElement)[2]
问题是我如何通过这个对象?主要目标是将其插入数据库。
任何帮助都将不胜感激。