2010-11-01 89 views
0

我在這個XML的文件格式:PHP的XML閱讀器字段類型

<?xml version="1.0" encoding="UTF-8"?> 
<?mso-application progid="Excel.Sheet"?> 

<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office"> 
<Styles> 
<Style ss:Name="Normal" ss:ID="Default"> 
<Alignment ss:Vertical="Bottom"/> 
<Borders/> 
<Font/> 
<Interior/> 
<NumberFormat/> 
<Protection/> 
</Style> 
<Style ss:Name="FormatedNumberBorderPatern" ss:ID="FormattedNumberBorderPatern"> 
<Alignment ss:WrapText="1" ss:Vertical="Center"/> 
<NumberFormat/> 
<Borders> 
<Border ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Bottom"/> 
<Border ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Left"/> 
<Border ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Right"/> 
<Border ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Top"/> 
</Borders> 
</Style> 
<Style ss:ID="s40"> 
<Alignment ss:Vertical="Bottom"/> 
<Font ss:Bold="1" ss:Color="#7A2A29" ss:Size="12" x:Family="Swiss" x:CharSet="204"/> 
</Style> 
<Style ss:ID="s25"> 
<Alignment ss:WrapText="1" ss:Vertical="Center" ss:Horizontal="Center"/> 
<Borders> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Bottom"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Left"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Right"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Top"/> 
</Borders> 
<Font ss:Bold="1" ss:FontName="Arial Unicode MS"/> 
</Style> 
<Style ss:ID="m155750108"> 
<Alignment ss:WrapText="1" ss:Vertical="Bottom"/> 
<Borders> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Bottom"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Left"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Right"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Top"/> 
</Borders> 
<Font ss:FontName="Arial Unicode MS"/> 
</Style> 
<Style ss:ID="empty"> 
<Alignment ss:Horizontal="Right"/> 
<Borders> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Bottom"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Left"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Right"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Top"/> 
</Borders> 
<Font ss:Bold="1" ss:FontName="Arial Unicode MS"/> 
</Style> 
<Style ss:ID="s30"> 
<Alignment ss:WrapText="1" ss:Vertical="Center" ss:Horizontal="Left"/> 
<Borders> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Bottom"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Left"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Right"/> 
<Border ss:Color="#000000" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Top"/> 
</Borders> 
<Font ss:FontName="Arial Unicode MS"/> 
</Style> 
</Styles> 
<Worksheet ss:Name="Information"> 
<Table border="1"> 
<Column ss:Span="1" ss:Width="192"/> 
<Row ss:Height="31.5" ss:AutoFitHeight="0"> 
<Cell ss:StyleID="s40"> 
<Data ss:Type="String">Обменни курсове за 29.10.2010</Data> 
</Cell> 
</Row> 
<Row/> 
<Row> 
<Cell ss:StyleID="s25"> 
<Data ss:Type="String">Валута</Data> 
</Cell> 
<Cell ss:StyleID="s25"> 
<Data ss:Type="String">Код</Data> 
</Cell> 
<Cell ss:StyleID="s25"> 
<Data ss:Type="String">За единици валута</Data> 
</Cell> 
<Cell ss:StyleID="s25"> 
<Data ss:Type="String">Лева (BGN)</Data> 
</Cell> 
<Cell ss:StyleID="s25"> 
<Data ss:Type="String">Обратен курс за 1 лев</Data> 
</Cell> 
</Row> 
<Row> 
<Cell ss:StyleID="s30"> 
<Data ss:Type="String">Австралийски долар</Data> 
</Cell> 
<Cell ss:StyleID="s30"> 
<Data ss:Type="String">AUD</Data> 
</Cell> 
<Cell ss:StyleID="FormattedNumberBorderPatern"> 
<Data ss:Type="Number">1</Data> 
</Cell> 
<Cell ss:StyleID="FormattedNumberBorderPatern"> 
<Data ss:Type="Number">1.37579</Data> 
</Cell> 
<Cell ss:StyleID="FormattedNumberBorderPatern"> 
<Data ss:Type="Number">0.726855</Data> 
</Cell> 
</Row> 

..和等。 我只需要這一行後,拔出數據:

<Cell ss:StyleID="s30"> 

這個XML被拉出的銀行(貨幣信息)。第一個字段是保加利亞貨幣的名稱,第二個是代碼(例如美元),第三個是金額,第四個是貨幣價值,第五個是您可以用一個保加利亞列弗購買多少貨幣BGN是我們的貨幣)。

我想創建一個貨幣轉換器,但XML的格式混淆了我。 有人能告訴我如何將所有貨幣的信息提取出來嗎?我需要在一個表中這些字段:

<Data ss:Type="String">Австралийски долар</Data> 
<Data ss:Type="String">AUD</Data> 
<Data ss:Type="Number">1</Data> 
<Data ss:Type="Number">1.37579</Data> 
<Data ss:Type="Number">0.726855</Data> 

這些線路重複(與單元格和行標籤一起)所有在XML文件中的貨幣。 您能否給我一個單一貨幣的例子?我如何解決這些領域的數據?

+1

央行提供連續更易於訪問的格式更新的外匯利率。請參閱[如何在PHP中實現匯率?](http://stackoverflow.com/questions/1973569/how-to-implement-exchange-rate-in-php/1973823#1973823)和[php script for currency conversion ](http://stackoverflow.com/questions/2635127/php-script-for-currency-conversion/2635428) – Gordon 2010-11-01 13:24:07

回答

1

該文件是一個XML Excel2003中的文件,在MS Excel 2003中引入了一個很少使用的SpreadsheetML格式,則有利於微軟的Office Open XML SpreadsheetML中的廢棄介紹了Excel2007的。通常這個文件是作爲一個zip壓縮文檔找到的。

PHPExcel具有此格式的閱讀器。我建議使用PHPExcel自己從文件中讀取數據,或者使用讀取器代碼作爲自己腳本的基礎來訪問您需要的信息。

+0

偉大的迴應,你是對的!我真的認爲這是一個XML文件..但它是XLS - 我從銀行獲得了錯誤的文件格式。我會得到正常的XML,所有應該工作。謝謝 ! – DreamWave 2010-11-01 13:31:38

+1

從技術上講,它是一個xml文件......只是不像你所期望的那樣結構化。 – 2010-11-01 13:34:38