Created
January 29, 2013 03:16
-
-
Save RalfAlbert/4661502 to your computer and use it in GitHub Desktop.
PHP XMLReader class example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can you also output the "element" of every "product"?