Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert RalfAlbert/data.xml
Created Jan 29, 2013

Embed
What would you like to do?
simplexml und xpath example
<?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>
<?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
You can’t perform that action at this time.