php XMLReader用法

来源:互联网 发布:淘宝店铺转让诈骗案 编辑:程序博客网 时间:2024/05/24 03:40

data.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<products>
<last_updated>2009-11-30 13:52:40</last_updated>
<product tax="19" name="luxus">
<element>foo</element>
</product>
<product tax="7" name="brot">
<element>bar</element>
</product>
</products>
xmlreader_class.php 文件如下:

<?php$xml = new XMLReader();$xml->open( 'data.xml' ); while( $xml->read() ) {if( 'product' === $xml->name ) {printf( '<hr>%3$s ist ein %1$s und hat eine Steuer von %2$d<br>', $xml->name, $xml->getAttribute('tax'), $xml->getAttribute('name') );$xml->next();}}


原创粉丝点击