You can use simpleXML with an XPath expression.
$xml = simplexml_load_file('myFile.xml'); $values = $xml->xpath('//td[@name]'); foreach($values as $v) { echo "Found $v<br />"; }
This will give you all the TD node values ββthat have a name attribute, for example.
Found 10/01/2009 Found Sample Promo Name Found Sample Promo Code Found <nothing cuz PromoLevel is empty>
Change To go through all the rows of the table, you can do something like this:
$rows = $xml->xpath('//tr'); foreach($rows as $row) { echo $row['id']; foreach($row->td as $td) { if($td['name']) { echo $td['name'],':',$td,'<br/>',PHP_EOL; } } }
You can also see this article .
Edit Fixed XPath expression as suggested by Josh.
source share