Created
January 29, 2013 09:32
-
-
Save RalfAlbert/4663019 to your computer and use it in GitHub Desktop.
simplexml und xpath 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> | |
<product tax="19" status="luxus"> | |
<element>Benzin</element> | |
</product> | |
<product tax="7" status="grundnahrung"> | |
<element>Brot</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 = simplexml_load_file('data.xml'); | |
$res = $xml->xpath('.//*[@tax]'); | |
foreach( $res as $node ) { | |
$atts = $node->attributes(); | |
printf( '%s ist %s und wird mit %d%% besteuert.<br>', $node->element, $atts['status'], $atts['tax'] ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment