Domanda

Ho un file XML in questo formato:

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

.. e così via. Ho solo bisogno di tirare fuori i dati dopo questa riga:

<Cell ss:StyleID="s30">

Questa xml è tirato fuori da una banca (che indicano la valuta). In primo campo è il nome della valuta in bulgaro, secondo è il codice (USD per un esempio), terzo è l'importo, avanti è il valore della moneta, quinto è la quantità di valuta che si può acquistare con un Lev bulgaro ( BGN è la nostra moneta).

Voglio creare un convertitore di valuta, ma la formattazione del XML mi confonde. Qualcuno può dirmi come posso tirare le informazioni su tutte le valute fuori? Ho bisogno di questi campi di una tabella:

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

Queste linee ripetono (insieme con il cellulare e tag riga) per tutte le valute del file xml. La prego di farmi un esempio per una moneta unica? Come faccio a indirizzare i dati in questi campi?

È stato utile?

Soluzione

Il file è un file XML Excel2003, un formato SpreadsheetML raramente utilizzato introdotto in MS Excel 2003, poi abbandonato a favore di Microsoft Office Open XML SpreadsheetML introdotto per Excel2007. Normalmente il file viene trovato in un archivio.

PHPExcel ha un lettore per questo formato. Io suggerirei sia utilizzando PHPExcel sé per leggere i dati dal file, oppure utilizzando il codice del lettore come base per il proprio script per l'accesso le informazioni necessarie.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top