I\'ve been searching for a while on this and haven\'t had much luck. I\'ve found plenty of resources showing how to echo data from dynamic XML, but I\'m a PHP novice, and nothi
Instead of using a for
loop, you can obtain the same result with XPath:
// Extraction splitted across two lines for clarity
$artist_xpath = $sxe->xpath('//info[@name="artist"]');
$artist = (string) $artist_xpath[0];
echo $artist;
You will have to adjust the xpath expression (i.e. change @name=...
appropriately), but you get the idea. Also notice that [0]
is necessary because xpath
will return an array of matches (and you only need the first) and the cast (string)
is used to extract text contained in the node.
Besides, your XML is invalid and will be rejected by the parser because of the literal &
appearing in the
tag.