0

我有一个这种格式的 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 文件中的所有货币,这些行重复(以及单元格和行标记)。你能给我一个单一货币的例子吗?如何处理这些字段中的数据?

4

1 回答 1

1

该文件是一个 Excel2003 XML 文件,它是 MS Excel 2003 中引入的一种很少使用的 SpreadsheetML 格式,然后被丢弃,取而代之的是为 Excel2007 引入的 Microsoft Office Open XML SpreadsheetML。通常,该文件以 zip 存档的形式找到。

PHPExcel有这种格式的阅读器。我建议要么使用 PHPExcel 本身从文件中读取数据,要么使用阅读器代码作为您自己的脚本访问所需信息的基础。

于 2010-11-01T13:24:01.927 回答