在php中显示来自xml的数据

时间:2014-09-18 10:20:47

标签: php xml-parsing

我将数据从xml文件下载到php时出现问题。单元格已编号,电子邮件地址未排列在列中。任何人都可以帮助我吗?

new.xml

   <Table ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25">
<Column ss:Index="2" ss:StyleID="s74" ss:AutoFitWidth="0" ss:Width="29.25"/>
<Column ss:StyleID="s74" ss:AutoFitWidth="0" ss:Width="192"/>
<Column ss:StyleID="s115" ss:AutoFitWidth="0" ss:Width="194.25"/>
<Column ss:AutoFitWidth="0" ss:Width="69.75"/>
<Row ss:Height="15">
<Cell ss:Index="2" ss:StyleID="s166">
</Cell>
<Cell ss:StyleID="s166">
<Data ss:Type="String">email</Data>
</Cell>
<Cell ss:StyleID="s166">
<Data ss:Type="String">Alias</Data>
</Cell>
</Row>
<Row>
<Cell ss:Index="2" ss:StyleID="s90">
<Data ss:Type="Number">1</Data>
<Cell ss:StyleID="s118">
<Data ss:Type="String">adam</Data>
</Cell>
<Cell ss:StyleID="s104"/>
</Row>
<Row>
<Cell ss:Index="4" ss:StyleID="s122" ss:HRef="mailto:adam@test.com.pl">
<Data ss:Type="String">adam@test.com.pl</Data>
</Cell>
</Row>
<Row>
<Cell ss:Index="4" ss:StyleID="s122" ss:HRef="mailto:adam.b@test.com.pl">...</Cell>
</Row>
<Row>
<Cell ss:Index="4" ss:StyleID="s122" ss:HRef="mailto:grp@test.com.pl">
<Data ss:Type="String">grp@test.com.pl</Data>
</Cell>
</Row>
<Row>
<Cell ss:Index="4" ss:StyleID="s122" ss:HRef="mailto:shop@test.com.pl">
<Data ss:Type="String">shop@test.com.pl</Data>
</Cell>
</Row>
<Row>
<Cell ss:Index="4" ss:StyleID="s123"/>  
</Row>
</Row>

这是我的PHP代码:

    <?php
$dom = new DomDocument();
$dom -> load("new.xml");
$data = $dom->getElementsByTagName('Data'); 
echo( "<table><tr>");
$n = 0;
foreach($data as $node)
{ 
if($n % 3 == 0) { echo '<tr>'; }
echo( "<td>". $node -> textContent . "<td>");
if(++$n % 3 == 0) { echo '</tr>'; }
}
echo( "</tr></table>");

?>

//编辑了xml文件

0 个答案:

没有答案