Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
Created January 29, 2013 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RalfAlbert/4663019 to your computer and use it in GitHub Desktop.
Save RalfAlbert/4663019 to your computer and use it in GitHub Desktop.
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