Question

I have a xml file in this format:

<?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>

..and so on. I only need to pull out data after this line:

<Cell ss:StyleID="s30">

This xml is pulled out of a bank (currency information). First field is the name of the currency in Bulgarian, second is the code (USD for an example), third is the amount, forth is the value of the currency, fifth is how much of the currency you can buy with one Bulgarian Lev (BGN is our currency).

I want to create a currency converter but the formatting of the XML confuses me. Can someone tell me how I can pull the information on all of the currencies out? I need these fields in a table:

<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>

These lines repeat (along with the cell and row tags) for all of the currencies in the xml file. Could you please give me an example for a single currency? How do I address the data in these fields?

Was it helpful?

Solution

The file is an Excel2003 XML file, a rarely used SpreadsheetML format introduced in MS Excel 2003, then discarded in favour of the Microsoft Office Open XML SpreadsheetML introduced for Excel2007. Normally the file is found as a zip archive.

PHPExcel has a reader for this format. I'd suggest either using PHPExcel itself to read the data from the file, or using the reader code as the basis for your own script to access the information you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top