0
我從遠程服務器拉取客戶端信息,並在我的網站上創建一個xml文件,這個文件將被解析爲一個網頁。使用此代碼:用simplexml解析xml的問題
$xml=simplexml_load_file("test.xml");
print_r($xml);
輸出以下:
SimpleXMLElement Object ([@attributes] => Array ([requestType] => schema))
下面是XML文件,因此也許有人可以看看有沒有輸出錯誤或東西:
<b1Reply:response requestType="schema">
<b1Reply:uri>/query/AccountBalance.aspx?CustCardCodeFrom=C1007&CustCardCodeTo=C1007</b1Reply:uri>
<b1Reply:status>OK</b1Reply:status>
<b1Reply:payload schemaDigest="ECDF0140846BF818A8A0605CB609BB7E">
<querydata queryName="/query//AccountBalance.aspx?CustCardCodeFrom=C1007&CustCardCodeTo=C1007">
<columns>
<column name="ID" alias="ID" type="Int64" key="false"/>
<column name="CompanyName" alias="CompanyName" type="String" key="false"/>
<column name="CompanyAddr" alias="CompanyAddr" type="String" key="false"/>
<column name="Phone" alias="Phone" type="String" key="false"/>
<column name="Fax" alias="Fax" type="String" key="false"/>
<column name="CompanyCurrency" alias="CompanyCurrency" type="String" key="false"/>
<column name="_CustStatmentHdr_CardCode" alias="CardCode" type="String" key="false"/>
<column name="_CustStatmentHdr_CardName" alias="CardName" type="String" key="false"/> <column name="_CustStatmentHdr_CardType" alias="CardType" type="String" key="false"/>
<column name="_CustStatmentHdr_Balance" alias="Balance" type="Decimal" key="false"/>
<column name="_CustStatmentHdr_BalanceFC" alias="BalanceFC" type="Decimal" key="false"/>
<column name="_CustStatmentHdr_BalanceSys" alias="BalanceSys" type="Decimal" key="false"/>
<column name="_CustStatmentHdr_Currency" alias="Currency" type="String" key="false"/>
<column name="_CustStatmentHdr_PymntGroup" alias="PymntGroup" type="String" key="false"/>
<column name="_CustStatmentHdr_GroupName" alias="GroupName" type="String" key="false"/>
<column name="_CustStatmentHdr_SlpName" alias="SlpName" type="String" key="false"/>
<column name="_CustStatmentDtl_TransId" alias="TransId" type="Int32" key="false"/>
<column name="_CustStatmentDtl_TransType" alias="TransType" type="Int32" key="false"/>
<column name="_CustStatmentDtl_DtlCardCode" alias="DtlCardCode" type="String" key="false"/>
<column name="_CustStatmentDtl_RefDate" alias="RefDate" type="DateTime" key="false"/>
<column name="_CustStatmentDtl_TaxDate" alias="TaxDate" type="DateTime" key="false"/>
<column name="_CustStatmentDtl_DueDate" alias="DueDate" type="DateTime" key="false"/>
<column name="_CustStatmentDtl_Ref1" alias="Ref1" type="String" key="false"/>
<column name="_CustStatmentDtl_Amount" alias="Amount" type="Decimal" key="false"/>
<column name="_CustStatmentDtl_SYSCred" alias="SYSCred" type="Decimal" key="false"/>
<column name="_CustStatmentDtl_SYSDeb" alias="SYSDeb" type="Decimal" key="false"/>
<column name="_CustStatmentDtl_SourceLine" alias="SourceLine" type="Int16" key="false"/>
<column name="_CustStatmentDtl_Document_ID" alias="Document ID" type="String" key="false"/>
<column name="_CustStatmentDtl_Customer_PO_No." alias="Customer PO No." type="String" key="false"/>
<column name="_CustStatmentDtl_Source_Document_ID" alias="Source Document ID" type="Int32" key="false"/>
<column name="_CustStatmentDtl_TranType" alias="TranType" type="String" key="false"/>
<column name="_CustStatmentDtl_DocAmount" alias="DocAmount" type="Decimal" key="false"/>
<column name="_CustStatmentDtl_JournalLine" alias="JournalLine" type="Int16" key="false"/>
</columns>
<data>
<row id="1">
<ID>2</ID>
<CompanyName/>
<CompanyAddr>address</CompanyAddr>
<Phone>555-555-5555</Phone>
<Fax>555-555-5555</Fax>
<CompanyCurrency>$</CompanyCurrency>
<_CustStatmentHdr_CardCode>C1007</_CustStatmentHdr_CardCode>
<_CustStatmentHdr_CardName>Card Name</_CustStatmentHdr_CardName>
<_CustStatmentHdr_CardType>C</_CustStatmentHdr_CardType>
<_CustStatmentHdr_Balance>168069.405000</_CustStatmentHdr_Balance>
<_CustStatmentHdr_BalanceFC>0.000000</_CustStatmentHdr_BalanceFC>
<_CustStatmentHdr_BalanceSys>168069.405000</_CustStatmentHdr_BalanceSys>
<_CustStatmentHdr_Currency>$</_CustStatmentHdr_Currency>
<_CustStatmentHdr_PymntGroup>NET 7 DAYS</_CustStatmentHdr_PymntGroup>
<_CustStatmentHdr_GroupName>Food Distribution</_CustStatmentHdr_GroupName>
<_CustStatmentHdr_SlpName>John Doe</_CustStatmentHdr_SlpName>
<_CustStatmentDtl_TransId>5036</_CustStatmentDtl_TransId>
<_CustStatmentDtl_TransType>13</_CustStatmentDtl_TransType>
<_CustStatmentDtl_DtlCardCode>C1007</_CustStatmentDtl_DtlCardCode>
<_CustStatmentDtl_RefDate>7/5/2013 12:00:00 AM</_CustStatmentDtl_RefDate>
<_CustStatmentDtl_TaxDate>7/5/2013 12:00:00 AM</_CustStatmentDtl_TaxDate>
<_CustStatmentDtl_DueDate>7/12/2013 12:00:00 AM</_CustStatmentDtl_DueDate>
<_CustStatmentDtl_Ref1>106346</_CustStatmentDtl_Ref1>
<_CustStatmentDtl_Amount>27709.610000</_CustStatmentDtl_Amount>
<_CustStatmentDtl_SYSCred>0.000000</_CustStatmentDtl_SYSCred>
<_CustStatmentDtl_SYSDeb>27709.610000</_CustStatmentDtl_SYSDeb>
<_CustStatmentDtl_SourceLine>1</_CustStatmentDtl_SourceLine>
<_CustStatmentDtl_Document_ID>106346</_CustStatmentDtl_Document_ID>
<_CustStatmentDtl_Customer_PO_No.>469</_CustStatmentDtl_Customer_PO_No.>
<_CustStatmentDtl_Source_Document_ID>1347</_CustStatmentDtl_Source_Document_ID>
<_CustStatmentDtl_TranType>Invoice</_CustStatmentDtl_TranType>
<_CustStatmentDtl_DocAmount>27709.610000</_CustStatmentDtl_DocAmount>
<_CustStatmentDtl_JournalLine>0</_CustStatmentDtl_JournalLine>
</row>
</data>
</querydata>
</b1Reply:payload>
<b1Reply:error/>
</b1Reply:response>
如果我嘗試回顯單個屬性,它將返回空白。我很茫然,在simplexml上也是一個noob。任何幫助表示讚賞。
好像解析工作正常,你有一個SimpleXMLElement對象 回。你有問題獲得某些屬性?你能否展示你正在試圖去獲得該屬性的價值?我想你最關心的'數據'節點是否正確? –
是的,我需要能夠基於每個客戶從xml返回特定值。我一直在討論simplexml手冊,似乎沒有任何東西可以返回數據。這裏是我從手冊中拉出的一個例子,並試過:'$ xmlStr = file_get_contents('test.xml'); \t $ xml = new SimpleXMLElement($ xmlStr); \t $ result = $ xml-> xpath(「data/Phone」); (list,$ node)= each($ result)){ while(list(,$ node)= each($ result)){echo'data/Phone:',$ node,「\ n」; }' – RiotAct